Chapter 4
Chapter 4
Chapter 4
Data representation in computers
Units of data representation
Computers speak binary. Binary language consists of combinations of 1's and 0's that represent
characters of other languages (in our case the English language). Don’t make the mistake of thinking that
little 1's and 0's are running around inside of the computer. We humans prefer to think of 1's and 0's
because it’s easier than visualizing positive and negative current flows or open and closed circuits which
is what actually happens inside computers.
Bit (Binary Digit): A bit of storage is like a light switch; it can be either on (1) or off (0). A
single bit is a one or a zero, a true or a false, a "flag" which is "on" or "off", or in general, the
quantity of information required to distinguish two mutually exclusive states from each other.
Gregory Bateson defined a bit as "a difference that makes a difference". The bit is the smallest
unit of storage used in computing. One digit in binary number system is called bit and
combination of eight bits is called a byte.
Byte: A byte is a contiguous sequence of a fixed number of bits. In recent years, the use of a byte
to mean 8 bits has become nearly ubiquitous. A combination of eight bits represents one character
in our language. One character in our language (eight bits) is referred to as a byte. Byte is the
basic unit that is used to represent the alphabetic and numeric data. (For example: 01000001 are a
byte that represents an uppercase A; each 1 or 0 is a bit.)
Word: Word refers the number of bits that a computer process at a time or a transmission
media transmits at a time. Mostly a word is a group of 16 bits. With 16 bits, you can
represent 216 (65,536) different values.
The more data stored or transmitted at once, the faster the process will be.
1
Compiled by Lingerew
Introduction to computer science 2015
Size of hard disk measured in:
a. Byte
b. Bit
Solution:
a) 1 GB = 230 byte
23 GB = y
y = 23 GB x 230 byte/1 GB
y = 23x230 byte
23 GB = y
y = 23 GB x 8 x 230 bit/1 GB
y = 23 x 8 x 230 bit
All the data entered in to computer, first converted in to the binary form and after processing, it
again converted to human-readable form.
Number system
In binary number system there can be only two choices for representing data. Either a
“0”or a “1”.The base or radix of binary system is 2.
Octal number system, here we have 8 possibilities (“0, 1, 2, 3, 4, 5, 6, and 7”). The base
or radix of octal number system is 8.
Hexadecimal number system, here we have 16 possibilities (“0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a,
b, c, d, e, and f”). The base or radix of hexadecimal number system is 16.
2
Compiled by Lingerew
Introduction to computer science 2015
In computer science, there are four commonly used bases - namely: base 2, base 8, base 10 and base 16.
And the number systems in these bases are binary, octal, decimal and hexadecimal respectively. The
following table summarizes these bases, their respective number systems and the possible digits
(symbols) for each base.
2 Binary 0 and 1
8 Octal 0-7
10 Decimal 0-9
Table below shows the correspondence between the binary system, octal and hexadecimal:
3
Compiled by Lingerew
Introduction to computer science 2015
a) (101.1)2
Solution
= 4 + 0 + 1 + 0.5
= (5.5)10
4
Compiled by Lingerew
Introduction to computer science 2015
b) (101011)2
Solution
(101011)2 => 1 x 20 =1
1 x 21 =2
0 x 22 =0
1 x 23 =8
0 x 24 =0
1 x 25 = 32
(43)10
c) (724)8
Solution
(724)8 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
(468)10
d) (ABC)16
Solution
(2748)10
Step 1 Converting the integral part of the decimal into integral part in the desired base
Step 2 Convert the fractional part of the decimal to a fractional number part in the desired base
Step 3 The number in the desired base consists of the integer obtained in step 1 followed by a base
point (dot) and then followed by the fractional number part obtained in step 2
Step 1 Explained:
5
Compiled by Lingerew
Introduction to computer science 2015
1. Divide the given integer by the base B
2. Repeat step 1 until a 0 quotient is obtained, using at each stage the quotient from the previous
stages as dividend and the base B as divisor.
The successive remainders (starting from the least significant end) are the successive digits of the
number in base B
Decimal to binary:-
Steps:-
2 27 remainder
2 13 1 =11011
2 6 1
2 3 0
2 1 1
0 1
Decimal to octal:- Steps:-
64 Remainder
8
8 0
8
1 0 =100
8
0 1
6
Compiled by Lingerew
Introduction to computer science 2015
Decimal to hexadecimal:-
Steps:-
Step 2 Explained:
.14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.
7
Compiled by Lingerew
Introduction to computer science 2015
b) (0.65)10 to binary
Solution
0.65 x 2 = 1.3
0.30 x 2 = 0.60
0.60 x 2 = 1.20
0.20 x 2 = 0.40
0.40 x 2 = 0.80
0.80 x 2 = 1.60
0.60 x 2 = 1.20
Answer = = (0.101001)2
Binary- to-Octal
Step:-
1. Divide the binary number into groups of three bits each beginning from
right side
2. Add 0s to the left, if last group is incomplete.
3. Convert each group into decimal.
Example1 convert (10101111)2 = ( ) 8
=10,101,111
=010,101,111
=2 5 7
(10101111)2 = (257)8
Octal-to-Binary
Step: 1.Convert each digit to octal number it equivalent three to its equivalent three digit
binary numbers all the binary group into a single groups.
2. Combine all the binary groups into a single group.
E.g.1 (53)8 = ( ) 2
(53)= 5 3
= 101 011
= (101011)2
8
Compiled by Lingerew
Introduction to computer science 2015
Example2: Convert the following octal numbers to binary
A) (705)8 =
7 0 5
b) (63.26)8 = (110 011.010 110)2
Step1 .Divide the binary number into groups to four bits each beginner from the right side.
2. Add 0 to the left, if the last group is incomplete.
3. Convert each group into decimal
E.g. (110101)2 = ( ) 16
=0011 0101
=3 5
= (35)16
Eg 2. (1111011110111011)2 = () 16
1111 0111 1011 1011
F 7 B C
(111101110101011)2 = (F7BC) 16
You can add 0’s on the right for fractional number or left for integral number, if
necessary, to form a complete quadruplets
Example3: convert the following binary number to hexadecimal
(1010111011)2 = (2 B B) 16
Hexadecimal-to-Binary
Step: 1 converting every digit i.e A to F of hexadecimal number (if any) to decimal
equivalent.
2. Convert every decimal number to it equivalent four digits binary number
Eg (35)16 = (_) 2
9
Compiled by Lingerew
Introduction to computer science 2015
3= (0011)2
5= (0101)2
(35)16 =(00110101)2
A)(10AF) 16 = 1 0 A F
Octal-to-Hexadecimal
This is equivalent to converting octal-to-binary and then to-hexadecimal
1 0 7 6
001 000 111 110
2 3 E
(1076)8 = (23E) 16
10
Compiled by Lingerew
Introduction to computer science 2015
Hexadecimal-to-Octal
This is equivalent to converting hexadecimal-to-binary and then to-octal
Solution
(1F0C) 16 = 1 F 0 C
0001 1111 0000 1100
001 111 100 001 100
1 7 4 1 4
(1F0C)16 = (17414)8
Remark: when you convert signed number, ignore the sign during conversion. After the number in the
desired base has been obtained, affix the sign of the original number to the desired number
Solution
(125)10 = (1000)5
Note: before you start converting a number to a specified base, check whether the given number is
valid one or not. If it is not, do not try to convert.
Miscellaneous Examples:
11
Compiled by Lingerew
Introduction to computer science 2015
2. Find the value of y if (1110)3 =(124)y
Solution
Exercise: For the following exercises, convert from the given base to the required base.
1. 454 to base 8
2. 225 to base 2
3. (256.75)10 to binary
4. (111110.11)2 to decimal
5. (10001010110.1101101)2 to octal
6. (10001010111.1101101)2 to hexadecimal
7. (ABEBE)16 to decimal
8. (ABEBE)16 to binary
9. (ABEBE)16 to octal
12
Compiled by Lingerew
Introduction to computer science 2015
BINARY ARITHMETIC
Binary numbers can be added, subtracted, multiplied and divided like natural
numbers/decimal numbers in which everybody uses them for day-to-day activities. Let’s
see how binary arithmetic is performed.
1. Binary addition
Rules
0+1=1
1+1=0 with carry 1 to the next digit
13
Compiled by Lingerew
Introduction to computer science 2015
Rules
1-1=0
1-0=1
0-1=1 borrows 1 from the highest digit
E.g. Subtract (10101)2 from (101110)2
Solution
101110
-10101
11001
3. Binary multiplication
Rules
1x1=1
0x1=0
1x0=0
E.g. 1. (1011.01)2 x (10.1)2
Solution
1011.01
x 10.1
101101
000000
14
Compiled by Lingerew
Introduction to computer science 2015
101101
(11100.001
4. Binary division
Rules
This rule works for a number in which the remainder becomes zero. It may work for non-zero
remainder numbers with some modifications.
a) Divide the dividend by the divisor until the remainder becomes zero or less than the
divisor (impossible to be divided).
b) When you take two or three etc. numbers of a dividend to add on the remainder part, you
have to add one zero (0) or two (00) etc. on the quotient respectively.
c) When you divide a number having fractional part, don’t worry about the fraction. Divide
the number as it is an integer number. But after you complete the division, count the
number of fractional digits from left to right to both the dividend (D) and divisor (Df).
Then the number of fractional parts of the quotient (Qf) from left to right is equal to the
difference between of D & Df.
d) Checking the result
Dividend=quotient * divisor + remainder
E.g.1. Divide (100001)2 by (11)2
Solution
Checking: 100001=11x1011 + 0
100001=100001
15
Compiled by Lingerew
Introduction to computer science 2015
Checking
1011.01=100.1x10.1 + 0
1011.01=1011.01
Note: If the difference between D & Df is negative, add zero(s) as many as the number of
the difference on the right side of the quotient. Let’s see it with an example.
E.g.3. Divide (101101)2 by (10.1)2
Solution
16
Compiled by Lingerew