Chapter 4
Chapter 4
Objectives:
To understand how really data represented, flow, stored and processed inside the
computer.
To know the different coding systems & unit of data representation.
To know different number systems
To know how to convert from one base to another
To know how to apply arithmetic operators on binary number system
We enter data into a computer or review (see) output data from a computer using the letter of
alphabet, various special symbols, and the numerals in the decimal number system. But since
computer is an electronic device which understands electrical flow (signal) there is no letter,
symbol or number inside the computer. Computer works with binary numbers. As a
semiconductor is conducting or isn’t conducting; a switch is closed or opened. It is not
surprising, therefore, that almost all of the present day computers are based on binary system
of representation that uses only two symbols – 1 and 0.
Any information stored in the computer system is first converted into binary number and then
stored in the computer memory or hard disk in the form of 1s and 0s.
For example, to convert 7 into binary number, we divide it by 2.
7/2
Number Remainder
2 7
2 3 1
1 1
When data is stored, processed or communicated within the computer system, it is packed in
units;
1
Arranged from the smallest to the largest, the units are called bit, byte and word;
These units are based on the binary number system;
BIT
Bits are the smallest units and can convey only two possible states 0 or 1; bit stands for binary
digits;
A bit is a single element in the computer, on a disk that stands for either “ON” indicating 1 or
“OFF” indicating 0;
In the computer “ON” is represented by the existence of current and “OFF” is represented by
the non existence of current
On a magnetic disk, the same information is stored by changing the polarity or magnetized
particles on the disk’s surface;
BYTE
Bits can be organized into large units to make them represent more and meaningful
information;
This large unit is called a byte and is the basic “unit of data representation” in a computer
system;
The commonly used byte contains 8 bits;
Since each bit has two states and there are 8 bits in a byte, the total amount of data that can be
represented is 28 or 256 possible combinations;
Each byte can represent a character(a character is either a letter, a number or a special symbol
such as +,-,?,*, $, etc
A byte is then used as a unit of measurement in the computer memory, processing unit,
external storage and during communication;
If the computer memory is 524288 byte, this is expressed in short by saying 512KB, where
KB stands for kilobyte.
1 Kilobyte(1KB) is 210 or 1024 bytes
1 Megabyte(MB) is 220 bytes or 210 kilobytes
1 Gigabyte(GB) is 230 bytes or 220 kilobytes or 210 megabytes
WORD
Word refers the number of bits that a computer process at a time or a transmission media
transmits at a time
Although bytes can store or transmit information, the process can even be faster if more than
one byte is processed at a once;
A combination of bytes, then form a “word”
A word can contain one, two, three or four bytes based on the capacity of the computer;
Word length is usually given in bits
We say that a computer is an 8-bits, a 16 bit, a 32 bit or a 64 bit computer to indicate that the
amount of data it can process at a time;
2
The large the word length a computer has the more powerful and faster it is.
CODING METHODS
It is possible to represent any of the character in our language in a way as a series of electrical
switches in arranged manner;
These switch arrangements can therefore be coded as a series of an equivalent arrangements
of bits
There are different coding systems that convert one or more character sets into computer
codes. Some are: BCD, ASCII, EBCDIC and Unicode is three of the most popular text coding
systems invented
BCD – Binary Coded Decimal
The BCD used a group of four bits to represent information in the computer system. It had a
maximum of 16 different alternative characters or numbers. It could represent only numbers
and some special symbols.
With BCD, each digit of a number is converted into its binary equivalent rather than
converting the entire decimal number to its binary form.
Example: The BCD value of the decimal number 5319 is 0101 0011 0001 1001
BCD (6-bits)
Coding Examples
BCD
Character Zone digits
A 11 0001
Q 10 1000
8 00 1000
9 00 1001
3
ASCII-7
ANSI's solution to representing symbols with bits of data was the ASCII character set. ASCII
(pronounced AS-key) stands for the American Standard Code for Information Interchange.
Today, the ASCII character set is by far the most commonly used in computers of all types.
Used widely before the introduction of ASCII-8 (the Extended ASCII)
Uses 7 bits to represent a character;
With the seven bits, 27( or 128) different characters can be coded (0000000-1111111)
It has a zone and digit bits positions
The characters from 0 to 31 and 127 are control characters;
from 32 to 64, special characters and numbers;
from 65 (A)to 96, uppercase letters and a few symbols;
From 97(a) to 126, lowercase letters plus a handful of common symbols.
Coding examples:
ASCII-7
Value Character Zone digit
36 $ 010 0100
37 % 010 0101
65 A 100 0001
66 B 100 0010
.
.
.
90 Z
97 a 110 0001
98 b 110 0010
.
.
.
122 z
4
Coding Examples
EBCDIC pronounced as “Eb-see-dick” and stands for Extended Binary Coded Decimal
Interchange Code.
It is an 8-bit coding scheme; (00000000 – 11111111)
It accommodates to code 28 or 256 different characters
It is a standard coding scheme for the large computers.
Coding Examples
EBCDIC
Character Zone Digit
a 1000 0001
b 1000 0010
A 1100 0001
B 1100 0010
0 1111 0000
9 1111 1001
Unicode
An evolving standard for data representation, called the Unicode Worldwide Character
Standard, provides 2 bytes (=16 bits) to represent each letter, number, or symbol.
With 2 bytes, enough Unicode codes can be created to represent more than 65,536 different
characters or symbols.
This total is enough for every unique character and symbol in the world, including the vast
Chinese, Korean, and Japanese character sets and those found in known classical and
historical texts.
One major advantage that Unicode has over other text code systems is its compatibility with
ASCII codes.
5
The first 256 codes in Unicode are identical to the 256 codes used by Extended ASCII
systems.
Unicode then extends far beyond the standard ASCII character set.
The Unicode standard was developed in 1991 by a joint engineering team from Apple
Computer Corporation and Xerox Corporation. It has been updated continually since its
inception.
In fall 1999, version three of the worldwide Unicode standard was released by the Unicode
Consortium, a group of developers, corporations, researchers, and other groups working in
conjunction with the ISO. In version three, the Unicode standard includes a total of 57,709 16-
bit code values.
Many software publishers, including IBM, Microsoft, Netscape, and others, encourage their
developers to use Unicode in their programs.
Unicode is supported by some operating systems (such as Windows 2000 and OS/2) and
applications. Even so, it has not yet been universally adopted by software developers.
Still, the goal is a worthwhile one. If a single character set were available to cover all
languages, computer programs and data would be interchangeable.
Number systems
There are different number systems. Some of are:
1. Decimal number systems
2. Binary number systems
3. Octal number systems
4. Hexadecimal number systems
6
For numbers greater than 9 it uses the symbols 0-9 to represent the number example 10
which is a combination of 1 and 0 and so on.
We say it is a base ten number system
Though it is widely used, it is inconvenient for computer to represent data. So we need
another number system.
7
Hexadecimal number system (16) (hex)
Suppose we had 16 fingers instead of 10 in case of 10 fingers they invented new symbols until
they exhausted all their fingers. Now they would have to invent new symbols because there
would have been some more fingers left unrepresented. These extra symbols are usually
represented by the letters at the beginning of the English alphabet.
It uses 16 symbols to represent numbers. But for the numbers greater than 15 they
represented in terms of the 16 symbols example 16 as 10 and so on.
When we compare the hexadecimal with decimal 0-9 in hexadecimal is the same as 0-9 in
decimal but 10 in hexadecimal is not the same as 10 in decimal, off course 10 in hexadecimal
is equal to 16 in decimal because it holds the position of 16 in decimal.
Conversion from one Base to Another
The values that members have within given number systems are largely determined by their
positional notation. Positional notation means that the position of one symbol relative to other
symbols in a given number system determines the value of that symbol. For example, these
symbols 1 & 7 can represent either 17 or 71 depending upon their relative position to one
another.
The decimal number 135 may be expanded as:
(135) 10 = 1*102+3*101+5*100
The subscript 10 is used to indicate that 135 is a base 10 number.
The number 10 in binary is not the same as 10 in decimal because the value of 1 in the binary
is not the same as the value of the 1 in the decimal.
The binary number 1101 may be expanded as
11012 = 1*23+1*22+0*21+1*20
= (1*8)+(1*4)+(0*2)+(1*1)
= 8+4+0+1
= 1310
A number X1 X2 X3 …Xn is bas M can be expanded as
(X0 X1 X2 X3 ..Xn)m=X1*mn-1+X2*mn-2X3*mn-3+ …X1*mn-1+Xnm0
8
Conversion from decimal (base 10) to other base (base M)
(Base 1 Base M)
9
Conversion from binary (base2) to Octal (base 8) or
hexadecimal (base16) and viceversal
To convert a number in binary to octal ,group three binary digits together starting from the last
digit (right and if there are no enough digits add zeros in front , (left) and find the
corresponding Octal of each group.
Example. Convert 1001001 to octal
1001001=001,001,001
= 1118
convert 101101001 to octal
101101001=101,101,001
=5518
To convert binary to hexadecimal group four binary digits together starting from right and if
there are no enough digits add zeros at the left.
EX. Convert 111100100 to hexadecimal
111100100=0001,1110,0100
= 1 14 4
= 1E416
To convert from Octal to binary , convert each octal digit to its equivalent 3 bit binary starting
from right.
EX. Convert (675)8 to binary
6758 =110 111 101
=1101111012
Convert 2318 to binary
2318 = 010 011 001
=100110012
To convert from Hexadecimal to binary convert each hex. Digit to its equivalent 4-bit binary,
starting from right.
10
Ex. Convert 23416 to binary
23416 =0010 0011 0100
= 10001101002
Convert 2AC to binary
2AC16 =0010 1010 1100
=10101011002
11
To convert BCD to decimal group into four & find its corresponding decimal.
Converting decimal number which contains fractions to Binary and Binary with
fraction to decimal.
First change the integer part to its equivalent binary. Multiply the fractional part by 2 and take
out the integer value, and again multiply the fractional part of the result by 2 and take out the
integer part, continue this until the product is 0.Collect the integer values from top to bottom
& concatenate with the integer part.
Ex.
B. Convert 12.2510 to binary
A) Convert 3.1875 to binary
– Convert 3 to binary >> (11)2
– Convert 0.1875 to binary
Hence 3.1875 = (11.0011)2
B) Convert 12.25 to binary (1100.01) 2
C) Convert 25.34 to binary.
To convert a binary number Y1Y2Y3Y4Yn.d1d2d3..dm to decimal, first convert the integer part to
decimal by using y1 y2 y3 y4…yn =y1*2n-1+y2*2n-2+….yj*2n-j+….+yn-1*21+yn*20=Q and convert
the fractional part to decimal by using d1d2d3…dm=d 1*2-1+d2*2-2+d3*2-3+…+dj*2-j+..+dm*2-
m
=R then decimal equivalence of y1 y2 y3 y4…..yn.d1d2…dm will be Q+R where Q is the integer
part and R is the fractional part.
12
Group three/ four digits together starting from the last of the integer part, and if there are no
enough digits add some zeros in the front.
Group three/ four digits together starting from the first of the fractional part, and if there are
no enough digits add some zeros to the last.
Convert each group of the integer and the fractional part to their equivalent Octal/hexa and
collect the results by adding point (.) to separate the integer part from the fractional part.
Binary Arithmetic
13
Computer understands only the language of binary numbers. Therefore, the machine
performs what is called binary arithmetic (binary computation).
Binary addition
Binary addition operates by the same rule as decimal addition, except that it is simpler. A
carry to the next higher order ( or more significant) position occurs when the sum is decimal
2, that is, binary 10. Therefore, the binary addition rules may be written as follows:
0+0=0
0+1=1
1+0=1
1+1=0 plus a carry of 1 into the next position
1+1+1=1 plus a carry of 1 into the next position.
The last case occurs when the two binary digits in a certain position are 1s and there is a carry
from the previous position.
Example;
Decimal = Binary Ex3 10011
6 + 110 + 11111
7 111 1010
13 1101 1001
1000101
Binary Subtraction
It operates by the same rule as decimal subtraction. The rule is as follows;
0-0=0
1-0=1
1-1=0
14
10-1=1
Example:
11100 101101 11001.011
- 11010 - 111 - 111.110
00010 101100 10001.101
Binary Multiplication:
- It is a very simple process that operates by the following obvious rules:
Multiplying any number by 1 will not change the multiplicand
0x1=0
1x1=1
Binary division
That is, the process for dividing one binary number (the dividend) by another
(the divisor) is based on the rules for binary subtraction and multiplication and
15
Similar to decimal division
Ex 1111101 11001
11001 101
11001
11001
00000
1111101 ÷ 11001 = 101
In signed binary representation, the left-most bit is used to indicate the sign of the number.
Traditionally, 0 is used to denote a positive number and 1 is used to denote a negative number.
But the magnitude part will be the same for the negative and positive values.
For example 11111111 represents-127 while 01111111 represents + 127.
We can now represent positive and negative numbers, but we have reduced the maximum
magnitude of these numbers to 127.
In a 5- bit representation, we use the first bit for sign and the remaining 4- bits for the
magnitude. So using this 5 bit representation the range of numbers that can be represented is
from -15 (11111) to 15(11111)
16
24=00011000
-24 = 1001100
In general, for n-bit sign –magnitude representation, the range of values that can be
represented are – (2 n-1-1) to (2 n-1-1).
i.e. 2 n-1 + 1 to 2 n-1 –1
2. One’s complement.
In one’s complement representation, all positive integers are represented in their correct
binary format. For example +3 is represented as usual by 00000011. However, its
complement, -3, is obtained by complementing every bit in the original representation. Each
0 is transformed into a1 and each 1 into a0. In our example, the one’s complement
representation of -3 is 11111111.
Ex: +2 is 00000010
-2 is 11111101
Note that in this representation positive numbers start with a 0 on the left, and negative
numbers start with a 1 on the left.
17
Ex1. Add -4 and +6
- 4 is 11111011
+ 6 is 00000110
the sum is (1) 00000001
Where 1 indicates a carry. The correct result should be 2 or 00000010.
Ex2:
-3+-2
-3 is 11111100
-2 is 11111101
11111001 or-6 plus a carry. The correct result is -5. The representation of –5 is 11111010.
This representation does represent positive and negative numbers: however, the result of an
ordinary addition does not always come out correctly. We will now use another
representation. It is evolved from the one’s complement and is called the two’s complement
representation.
18
(-5) + 111111011
11111110
Ex. add +4 and -3(the subtraction is performed by adding the two’s complement).
+4 is 00000100
-3 is 111111101
The result is [1] 000000001
If we ignore the carry the result is 00000001 ( i. e 1 In decimal). This is the correct result. In
two’s complement, it is possible to add or subtract signed numbers, regardless of the sign.
Using the usual rules of binary addition, the result comes out correct, including the sign. The
carry is ignored. One’s complement may be used, but if one’s complement is used, special
circuitry is required to “correct the result”.
Ex (128) 10000000
+ (129) = 10000001
[257] = (1) 00000001
Where 1 indicates a carry. The result requires a ninth bit (bit 8, since the right- most bit is 0).
It is the carry bit.
If we assume that the carry is the ninth bit of 100000001= 257. However, the carry must be
recognized and handled with care. Inside the microprocessor, the registers used to hold
information are generally only eight bits wide. When storing the result, only bits 0 to 7 will
be preserved.
Overflow
Bit 7 bit 6
Fixed format representation: We now know how to represent signed integers: however, we
have not yet resolved the problem of magnitude. If we want to represent large integers, we
will need several bytes. In order to perform arithmetic operations efficiently, it is necessary to
use a fixed number of bytes, rather than a variable number. Therefore, once the number of
bytes is chosen, the maximum magnitude of the number that can be represented is fixed.
20
If the result is ( n+1)-bit number, and the arithmetic is in ones complement the (n+1) th bit, a
carry, is added to the right most bit of the result. This process is called an end-around carry.
Two’s complement discard the (n+1) th bit.
An n-bit number and the arithmetic is in ones complement, to read the binary value, calculate
the ones complement of the magnitude and place a minus sign in front of it.
Two’s complement, to read the binary value, calculate the two’s complement of the
magnitude and place a minus sign in front of it.
Example:
Perform the following in ones and two’s complements in 5-bits.
a. 12-6
b. 6-12
c. -12-6
a) In ones complement:
ones complement of 6=11001
12 01100
-6 + 11001
100101
carry
Add the carry at the LSB.
The result is 00101
+1
(6) 00110
In two’s complement:
two’s complement of 6 = 11001 + 1= 11010
12 01100
-6 + 11010
100110
Carry to be added
i.e. The result is 01100 + 1 = 01101 which is wrong
In 2’s complement:
2’s complement of 12 is: 10011 +1 = 10100
2’s complement of 6 is 11001
-12 10100
-6 + 11010
-18 101110
Floating-Point Representation
22
In this representation decimal numbers are represented with a fixed length format. In order
not to waste bits, the representation will normalize all the numbers. For example, 0.000123
wastes three zeroes on the left before non -zero digits. There zeroes have no meaning except
to indicate the position of the Decimal point. Normalizing this number result in .123x10 -3 .123
is the normalized mantissa; -3 is the exponent. We have normalized this by eliminating all the
meaningless zeroes to the left of the first non-zero digit and by adjusting the exponent.
Ex1: 22.1 is normalized as .221x102.
The general form of floating point representation is Mx10E where M is the mantissa, and E is
the exponent .It can be seen that a normalized number is characterized by a mantissa less then
1 and greater than or equal to.1 all cases when the number is not zero.
In representing a number in floating point, we use 1 bit for sign, some bits for exponent and
the remaining bits for mantissa.
In floating point representation the exponent is represented by a biased exponent
(Characteristic).
Biased exponent = true exponent + excess 2n-1, where n is the number of bits representing the
exponent.
Ex1. Represent –234.375 in floating point using 7 bit for exponent and 16 bit for mantissa.
First we have to change to normalized binary
i. e 234 = 11100010 and 0.375= 0.011
234.375 = 11100010.011 = 0.11100010011x28
true exponent = 8
excess 2 n-1 = 2 7-1= 26= 64
Biased exponent = 8+26 =8+64 = 72 = 1001000 2
23
Therefore –234.375 is represented as:
1 1001000 1110001001100000
Ex2. Represent 34.25 in floating point using 7 bit for exponent and 24 bits for mantissa.
34.25 = 1000 10.0 12
The normalized form in binary of 34.25 = .10001001x 26
True exponent = 6
Excess 2n-1 = 27 -1 = 64
Biased exponent= 6+64 = 70 = 10001102
23.37+41.25 = 0.01011101x26+0.1110010x26
= (0.010111011+0.11100101)26
= 0.1010000101x26
25