4 Chapter Four - 2 16365
4 Chapter Four - 2 16365
CHAPTER FOUR
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. So data are
represented in the form of a code that can have a corresponding electrical
signal.
BIT:
Bits are the smallest units and can convey only two possible states 0 or
1;
A bit is a single element in the computer, on a disk that stands for either
“ON” indicating 1 or “OFF” indicating 0;
BYTE:
Bits can be organized into large units to make them represent more and
1 of 16
DATA REPRESENTATION IN COMPUTERS
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 using a single byte is 2 8 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).
WORD:
Since the early days of human civilization, people have been using their fingers,
sticks, and other things for counting. As daily activities became more complex,
numbers became more important in trade, time, distance, and in all spheres of
human life. A number system defines a set of values used to represent quantity.
There are various number systems e.g. decimal, binary, octal, hexadecimal, etc
2 of 16
DATA REPRESENTATION IN COMPUTERS
each differs one another by the number of symbols used in the system. Each
numbering system used different symbols to represent a given quantity.For a
computer, everything is a number whether it may be numbers, alphabets,
punctuation marks, its own instructions, etc. The number systems that are
generally used by computers are: decimal, binary, octal, and hexadecimal.
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)
Computers do not use the ten digits of the decimal system for counting and
arithmetic. Their internal structure (mainly the CPU and memory) are made up
of millions of tiny switches that can be either in an ON or OFF states. 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.
3 of 16
DATA REPRESENTATION IN COMPUTERS
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).
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.
4 of 16
DATA REPRESENTATION IN COMPUTERS
2 44 Remainder
2 11 0
2 5 1
2 2 1
2 1 0
1
LSB (List 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.
5 of 16
DATA REPRESENTATION IN COMPUTERS
number.
Example: Determine the decimal equivalent of (100100)2
1*25 + 0*24 + 0*23 + 1*22 + 0*21 +0*20 = 32+4 =36
Therefore, the decimal equivalent of (100100)2 is 36
In general To convert a number X consists of digits X 1 X2 X3 …Xn in base m to decimal;
simply expand the number with base m. That is
(X1X2X3…Xn) m =X1*mn-1+X2*mn-2 +X3*mn-3+...+ Xi*mn-i+… Xn-1m1+Xn*m0
=Y10
Example: convert (234)8 to decimal
=2*82 + 3*81 + 4*80 = 128+24+4 = 156
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 B F
=1 E 4 =(1BF)16
= (1E4)16
To convert from Octal to binary, convert each octal digit to its equivalent 3 bit binary
starting from right.
6 of 16
DATA REPRESENTATION IN COMPUTERS
=(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
7 of 16
DATA REPRESENTATION IN COMPUTERS
8 16 Go from 8 …….2…….16
16 8 Go from 16 …….2…….8
8 of 16
DATA REPRESENTATION IN COMPUTERS
Group three/ four digits together starting from the first digit of the fractional part, and
if there is less number of digits add some zeros to the end.
Covert each group of the integer and the fractional part to their equivalent
Octal/hexadecimal and collect the results by adding point (.) to separate the integer part
from the fractional part.
Ex 1:- Covert 1010.01112 to octal
Ex2:- Covert 1110101.101112 to hexadecimal
Conversion from Octal or Hexadecimal with Fraction to Binary
Convert each Octal/hexadecimal digit to its equivalent 3/4-bit binary digit.
Collect the binary sequences by separating the integer part binaries from the
fractional part binaries with point (.)
Conversion from Octal with Fraction to Hexadecimal
To convert from Octal to hexadecimal, first convert the Octal to binary and then the
binary to hexadecimal
Conversion from Hexadecimal with Fraction to Octal
To convert from hexadecimal to Octal, first convert the hexadecimal to binary and
then the binary to Octal.
Conversion from Octal/Hexadecimal with Fraction to Decimal.
To convert from Octal/hexadecimal to decimal, first convert to binary and –then the
binary to decimal.
4.2.6 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)
9 of 16
DATA REPRESENTATION IN COMPUTERS
Adding two "1" values produces the value "10" (spoken as "one-zero"), equivalent to the
decimal value 2. This is similar to what happens in decimal when certain single-digit
numbers are added together; if the result equals or exceeds the value of the radix (10), the
digit to the left is incremented: e. g 5 + 5 = 10 , 7 + 9 = 16 .This is known as carrying in
most numeral systems. 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
In this example, two numerals are being added together: 011012 (13 decimal) and 101112
(23 decimal). The top row shows the carry bits used. Starting in the rightmost column,
1 + 1 = 102. The 1 is carried to the left, and the 0 is written at the bottom of the rightmost
column. The second column from the right is added: 1 + 0 + 1 = 10 2 again; the 1 is
carried, and 0 is written at the bottom. The third column: 1 + 1 + 1 = 11 2. This time, a 1 is
carried, and a 1 is written in the bottom row. Proceeding like this gives the final answer
1001002 (36 decimal).
10 of 16
DATA REPRESENTATION IN COMPUTERS
- 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.
Since there are only two digits in binary, there are only two possible outcomes of each
partial multiplication:
If the digit in B is 0, the partial product is also 0
If the digit in B is 1, the partial product is equal to A
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
11 of 16
DATA REPRESENTATION IN COMPUTERS
---------------
=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:
101
__________
101 |11011
−101
-----
011
−000
-----
111
−101
-----
10
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 10 2. In decimal, 27 divided by 5 is 5, with a
remainder of 2.
12 of 16
DATA REPRESENTATION IN COMPUTERS
13 of 16
DATA REPRESENTATION IN COMPUTERS
14 of 16
DATA REPRESENTATION IN COMPUTERS
15 of 16
DATA REPRESENTATION IN COMPUTERS
Coding Examples:
Character zone (3 BIT) digit (4 BIT) a 0110 0001
0-9 3 0-9 b 0110 0010
A-O 4 1-15 A 0100 0001
P-Z 5 0-10 B 0100 0010
a-o 6 1-15 ? 0011 1111
p-z 7 0-10 + 0010 1011
1 0011 0001
Unicode
Unicode has started to replace ASCII and other coding methods at all levels. It enables
users to handle not only practically any script and language used on this planet; it also
supports a comprehensive set of mathematical and technical symbols to simplify
scientific information exchange. Unicode provides a unique number for every character,
no matter what the platform, no matter what the program, no matter what the language.
Unicode was originally designed to be a 16-bit code, but it was extended so that currently
code positions are expressed as integers in the hexadecimal range 0..10FFFF (decimal
0..1 114 111).
16 of 16