Chapter 4 Data Representation
Chapter 4 Data Representation
1 of 10
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, four or eight bytes based on the capacity of the computer.
Word length is usually given in bits. We say that a computer is an 8-bit, a 16 bit, a 32 bit or a 64
bit computer to indicate that the amount of data it can process at a time. The larger the word
length a computer has the more powerful and faster it is.
Concept of Number Systems and Binary Arithmetic
A number system defines a set of values used to represent quantity. There are various number
systems e.g. decimal, binary, octal, hexadecimal, etc each differs one another by the number of
symbols used in the system. Each numbering system used different symbols to represent a given
quantity. The number systems that are generally used by computers are: decimal, binary, octal,
and hexadecimal.
The Decimal Number System
The primary number system used is a base ten number system or decimal number system. The
Decimal number system is based on the ten different digits or symbols (0,1,2,3,4,5,6,7,8,9).
Starting at the decimal point and moving to the left, each position is represented by the base
(radix) value (10 for decimal) raised to power. The power starts at Zero for the position just to
the left of the decimal point. The power incremented for each positions that continues to the left.
Moving to the right of the decimal point is just like moving to the left except that we will need
to place a minus sign in front of each power.
For example: (8762)10 = (8*103) + (7*102) + (6*101) + (2*100)
(0.475)10= (4*10-1) + (7*10-2) + (5*10-3)
The Binary number system
Computers do not use the ten digits of the decimal system for counting and arithmetic. Two
digits, 0 and 1, are used to refer for these two states.
Binary number system is based on the two different digits; 0 and 1. With binary number system,
it is very easier for the hardware to represent the data. Binary number system is base two
number system.
For example: (01100)2, (10110.011)2 , etc
2 of 10
Octal number system
The octal number system with its eight symbols (0, 1, 2, 3, 4, 5, 6, and 7) is a base 8 system.
For example: (322)8, (10.25)8, etc
Hexadecimal number system
Hexadecimal number system is another number system that works exactly like the decimal and
binary number systems, except that the base is 16. It uses 16 symbols (0-9, and A-F characters
to represent 10-15).
For example: (8F0)16, (D.45)16, etc
Conversion between Number Systems
Computers use binary numbers for internal data representation whereas they use decimal
numbers externally. Therefore, there should be some conversion between number systems in
order to represent data in a computer that is originally represented in other number systems.
Some conversion methods are discussed below.
Decimal to Binary
It is important to note that every decimal number system has its equivalent binary number. For
example:
Binary Decimal Binary Decimal
0 0 101 5
01 1 110 6
10 2 111 7
11 3 1000 8
100 4 1001 9 etc
Conversion from binary to its equivalent decimal and from decimal to its equivalent binary is
possible. The method, which is used for the conversion of decimal into binary, is often called as
the remainder method. This method involves the following steps.
- Begin by dividing the decimal number by 2 (the base of binary number system)
- Note the remainder separately as the rightmost digit of the binary equivalent
- Continually repeat the process of dividing by 2 until quotient is zero and keep writing the
remainders after each step of division (these remainders will either be 0 or 1)
- Finally, when no more division can occur, write down the remainders in reverse order (last
remainder written first)
3 of 10
Example: Determine the binary equivalent of (44)10
2 44 Remainder
2 11 0
2 5 1
2 2 1
2 1 0
1
1
MSB (Most Significant Bit)
Taking the remainder in reverse order we have 101100. Thus the binary equivalent of (44) 10 is
(101100)2
In general to convert a decimal number X to a number in base M, divide X by M, store the
remainder, again divide the quotient by M, store the remainder, and continue until the quotient
is 0. And concatenate (collect) the remainders starting from the last up to the first.
4 of 10
Example: convert (A1B) 16 to decimal
=A*162 + 1*161 + B*160 = 2587
Binary (base2) to Octal (base 8) or hexadecimal (base16) and vice versa
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 to the front end (left) and find the
corresponding Octal of each group.
Example: Convert 1001001 to octal Convert 101101001 to octal
1001001=001,001,001 101101001 =101,101,001
= 1118 =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.
Example: Convert 111100100 to Convert 111001111 to Hexadecimal
hexadecimal 111001111 =0001 1100 1111
111100100 =0001 1110 0100 =1 12 15
=1 14 4 =1 C F
=1 E 4 =(1CF)16
= (1E4)16
To convert from Octal to binary, convert each octal digit to its equivalent 3 bit binary starting
from right.
Example: Convert (675) eight to binary Convert 231eight to binary
=(110111101)two =(10011001)two
To convert from Hexadecimal to binary convert each hex. Digit to its equivalent 4-bit binary
starting from right.
Example: Convert 23416 to binary Convert 2AC to binary
23416 =0010 0011 0100 2AC16 =0010 1010 1100
= 10001101002 =10101011002
5 of 10
Octal to hexadecimal and Vice versa
To convert from Octal to hexadecimal, first we have to convert to binary and the binary to
hexadecimal. To convert from hexadecimal to Octal, first we have to convert to binary and then
the binary to Octal.
Example: Convert 2358 to hexadecimal Convert (1A)16 to Octal
2388=010 011 101 1A=0001 1010
=0000 1001 1101 =000 011 010
=0 9 13 = 0 3 2
=9D16 =328
Binary Arithmetic
Arithmetic in binary is much like arithmetic in other numeral systems. Addition, subtraction,
multiplication, and division can be performed on binary numerals. The simplest arithmetic
operation in binary is addition. Adding two single-digit binary numbers is relatively simple:
0+0=0
0+1=1
1+0=1
1 + 1 = 10 (carry:1)
When the result of an addition exceeds the value of the radix, the procedure is to "carry the one"
to the left, adding it to the next positional value. Carrying works the same way in binary:
1 1 1 1 1 (carried digits)
01101
+10111
-------------
=100100
Subtraction works in much the same way:
0−0=0
0 − 1 = 1 (with borrow)
1−0=1
1−1=0
One binary numeral can be subtracted from another as follows:
** * (starred columns are borrowed from)
6 of 10
100101
− 1011
----------------
=011010
The following steps are involved:
- First, for the least significant bit(the right most bit) , 1-1 is 0
- For the next bit, 0-1 cannot be computed since the subtrahend is smaller than the
minuend. Borrow 1 from the third bit to form the binary number 10 (decimal 2) and
do the subtraction. The operation is 10-1=1 which in decimal number system is 2-
1=1
- For the third bit, since we borrowed 1 for the second bit, we have 0-0 that is 0
- For the forth bit again, we cannot perform the subtraction. However the fifth bit in
the minuend is zero, so we must borrow from the sixth bit. This makes the fifth bit
10 (decimal 2). Borrowing from the fifth bit makes it 1 and the fourth bit become 10
(decimal 2). Now the subtraction in binary is 10-1=1 which is the result of the fourth
bit.
- For the fifth bit, we now have 1-0=1
- Since we borrowed 1 from the sixth bit for the fourth bit, so for the sixth bit, the
subtraction is 0-0=0
Multiplication in binary is similar to its decimal counterpart. Two numbers A and B can be
multiplied by partial products: for each digit in B, the product of that digit in A is calculated and
written on a new line, shifted leftward so that its rightmost digit lines up with the digit in B that
was used. The sum of all these partial products gives the final result.
For example, the binary numbers 1011 and 1010 are multiplied as follows:
1 0 1 1 (A)
× 1 0 1 0 (B)
---------
0 0 0 0 ← Corresponds to a zero in B
+ 1011 ← Corresponds to a one in B
+ 0000
+1011
---------------
7 of 10
=1101110
Binary Division is again similar to its decimal counterpart:
__________
101 |11011
Here, the divisor is 1012, or 5 decimal, while the dividend is 11011 2, or 27 decimal. The
procedure is the same as that of decimal long division; here, the divisor 101 2 goes into the first
three digits 1102 of the dividend one time, so a "1" is written on the top line. This result is
multiplied by the divisor, and subtracted from the first three digits of the dividend; the next digit
(a "1") is included to obtain a new three-digit sequence:
1
_________
101 |11011
−101
-----
011
The procedure is then repeated with the new sequence, continuing until the digits in the
dividend have been exhausted:
Thus, the quotient of 110112 divided by 1012 is 1012, as shown on the top line, while the
remainder, shown on the bottom line, is 102. In decimal, 27 divided by 5 is 5, with a remainder
of 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
a 1 and each 1 into a 0. In our example, the one’s complement representation of -3 is 11111100.
Example: +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 most bit.
Example 1: add –3 and 3 with word size 4
3 = 0011
-3=1100
sum =1111 (=0)
Ex2. Add -4 and +6
8 of 10
- 4 is 11111011
+ 6 is 00000110
The sum is (1) 00000001
Where 1 indicates a carry. The correct result should be 2 or 00000010.
In one’s complement addition and subtraction, if there is an external carry it should be added to
get the correct result. This indicates it requires additional circuitry for implementing this
operation.
Two’s Complement Representation
In two’s complement representation, positive numbers are represented, as usual, in singed
binary, just like in one’s complement. The difference lies in the representation of negative
numbers. A negative number represented in two’s complement is obtained by first computing
the one’s complement and then add one.
Example: +3 is represented in signed binary as 00000011
Its one’s complement representation is 11111100.
The two’s complement is obtained by adding one.
It is 11111101.
Example: let’s try addition.
(3) 00000011
+ (5) +00000101
(8) 0001000
The result is correct
Example: Let’s try subtraction
(3) 00000011
(-5) + 111111011
11111110
Example : 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 external 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
9 of 10
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”.
Carry and overflow
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.
The two’s complement representation has one anomaly not found with sign magnitude or one’s
complement. The bit pattern 1 followed by N-1 zeros is its own 2’s complement. To maintain
N
sign bit consistency, this bit pattern is assigned the value –2 for example, for 8-bit word,
-128 = 10000000
its 1’s complement =01111111
+1
=100000000 = -128
10 of 10