0% found this document useful (0 votes)
28 views16 pages

Chapter 4

Uploaded by

Guyyaa Tokko Ifa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views16 pages

Chapter 4

Uploaded by

Guyyaa Tokko Ifa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to computer science 2015

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.

 A combination of bytes, then form a “word”


 A word can contain 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;
 The large the word length a computer has the more powerful and faster it is.

1
Compiled by Lingerew
Introduction to computer science 2015
Size of hard disk measured in:

• Kilobytes, Megabytes, and Gigabytes

KB (Kilo byte): A kilo byte is 210 bytes = 210 x 8 bits

MB (Megabyte): A megabyte is 220 bytes = 220 x 8 bits

GB (Giga byte): A giga byte is 230 bytes = 230 x 8 bits

TB (Tera byte): A tera byte is 240 bytes =240 x 8 bits

Example 1: If a storage device is 23 GB, find the memory capacity 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

b) 1GB = 8 x 230 bit

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.

Base Number System Possible Symbols(digits)

2 Binary 0 and 1

8 Octal 0-7

10 Decimal 0-9

16 Hexadecimal 0-9 and A-F

Summary of Number systems

Table below shows the correspondence between the binary system, octal and hexadecimal:

Decimal Binary Octal Hexadecimal


0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

3
Compiled by Lingerew
Introduction to computer science 2015

Steps to represent a data on computer

Conversion System from One base to another


I. Conversion of any-base Number to a Decimal Number
A number that is represented in any base can be converted to decimal using the following steps:

Step 1. Represent the given number in its general form

Step 2. Using decimal arithmetic simplify the general form

Example 1: convert the following numbers to decimal

a) (101.1)2

Solution

(101.1)2 = 1x22 + 0x21 +1x20 +1x2-1

= 1x4 + 0x2 + 1x1 + 1x ½

= 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

(ABC)16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560

(2748)10

Conversion from Decimal (Base 10) to another Bases


A decimal number might have two parts: integral (left of the point) and fractional (to the right of the
point) parts. Converting these two parts from base 10 to any other base involves the following steps:

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:

To convert a decimal integer to a base B integer number

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:-

1. Divide the number by 2 and store the remainder.


2. Divide the quotient by 2 and store the remainder.
3. Repeat these steps until quotient becomes 0.
4. Write the remainders from bottom to top order.

Example1 convert 27 into binary

2 27 remainder
2 13 1 =11011
2 6 1
2 3 0
2 1 1
0 1
Decimal to octal:- Steps:-

1. Divide the number by 8 and store the remainder.


2. Divide the quotient by 8 and store the remainder.
3. Repeat these steps until quotient becomes 0.
4. Write the remainders from bottom to top order.

Example 1 converts 64 into octal

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:-

1. Divide the number by 16 and store the remainder.


2. Divide the quotient by 16 and store the remainder.
3. Repeat these steps until quotient becomes 0.
4. Write the remainders from bottom to top order.

Example 1 Convert 1715 in to hexadecimal

1715 remainder hexadecimal


16 equivalent
107 3 3
16
6 11 B =6B3
16
0 6 6

Step 2 Explained:

To convert a decimal fraction to a fraction in base B

1. Multiply the given decimal fraction in base B


2. Repeat step 1 using the multiplicand at each step the remaining fractional part from the
previous step until a fractional part is identically 0, or until as many digits as desired have
been generated. The successive integral parts are the successive digits of the number in base
B starting from the most significant end.
Example: convert the following decimal numbers to binary. E.g a) 3.14579 to binary

.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

Example2 convert (110 011.010 110)2 = (63.26)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

c) (65.61)8 = (110 101.110 001)2


(705)8 = (111 000 101) 2
Binary-to-Hexadecimal

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

A)(1010111011)2= (10 1011 1011)

(1010111011)2 = (2 B B) 16

b) (11 0011.0101 10)2 = (33.58)16

c) (11 1100 1011.1001 1)2 = (3CB.98)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

Example2: convert the following hexadecimal numbers to binary

A)(10AF) 16 = 1 0 A F

(10AF) 16 = (0001 0000 1010 1111)2

b) (33.58)16 = (0011 0011.0101 1000)2

c) (4E93)16 = (0100 1110 1001 0011)2

Octal-to-Hexadecimal
This is equivalent to converting octal-to-binary and then to-hexadecimal

Example: convert (1076)8 to hexadecimal

1 0 7 6
001 000 111 110

0010 0011 1110

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

Example: convert (1F0C) 16 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

Example: convert (-125)10 to base 5

Solution

(125)10 = (1000)5

=> (-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.

Example: (230)2 is illegal and same is true for (98)8

Miscellaneous Examples:

1. Find the value of y if (123y)16 = (11074)8


Solution
1x163 + 2x162 + 3x161 +yx160 = 1x84 + 1x83 +0x82 +7x81 +4x80

 1x4096 + 2x256 + 3x16 + yx1 = 4668


 4096 + 512 + 48 +y = 4668
 4656 + y = 4668
 y = 4668 – 4656
 y =12
 y=C

11
Compiled by Lingerew
Introduction to computer science 2015
2. Find the value of y if (1110)3 =(124)y
Solution

1x33 + 1x32 + 1x31 + 0x30 = 1xy2 + 2xy1 + 4xy0



1x27 + 1x9 +1x3 + 0x1 = y2 + 2y + 4

27 + 9 + 3 + 0 = y2 + 2y + 4

y2 + 2y + 4-39 = 0

y2 + 2y - 35 = 0

(y – 5) (y + 7) = 0

y = 5 or y = -7
Therefore, since the base cannot be negative, the answer is y = 5

Exercise: For the following exercises, convert from the given base to the required base.

No. Question Answer

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

10. ( 648)2 to hexadecimal

11. 171 to base 16

12. (256.75)10 to hexadecimal

13. (29y)16 = 671, then find the value of “y”

12
Compiled by Lingerew
Introduction to computer science 2015

Some example of ASCII code

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

1+1+1=1 with carry 1 to the next digit


1+1+1+1=0 with carry 2 to the next digit
E.g. Add (10111)2 and (110101)2
Solution
110101
+10111
1001100
2. Binary subtraction

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

E.g. 2. Divide (1011.01)2 by (10.1)2


Solution

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

You might also like