Data Represenatation in Digital Logic
Data Represenatation in Digital Logic
Data Representation
DATA TYPES.
Data is a term used to describe a set of facts. A single fact is known as Datum.
Data can be in 3 types or forms.
1. Numeric data (numbers)
2. Alphabetic data.
3. Alphanumeric data.
Numbers:
Numbers can be expressed as either;
Integers - whole numbers, e.g., 124, -26, or
Real numbers - numbers with decimal points, e.g., 1.23, -2.6.
Note. A whole number is Real if it is written with a decimal point, e.g., 25 is an integer, but 25.0
is real.
Alphabetic data:
This is data made from combination of alphabetic characters, such as names, title, marital status,
e.g. “John”, “Prof.”, “Married”.
Alphanumeric data (Strings):
A string is any sequence of characters.
This is data made from combination of alphabetic characters, numerals and/or special characters.
Examples;
Names - NG’ANG’A, ANN NDUVA
Address - P.O BOX 299, UGUNJA
Date - November 14, 1990
Account numbers - AO133
Department - Sales department
Messages - Incorrect. Try again
Exercise.
1. Explain the terms Numeric and Alphanumeric. Illustrate your answers with appropriate
examples.
Data Representation
THE BYTE.
The capacity of a computer memory can be measured in terms of Bits (individual memory cells),
Bytes (groups of cells or bits) or Words (arrangement of the bytes).
A Bit (Binary digit) is the number 0 or 1 in the representation of a value in binary notation.
A Byte is a fixed number of adjacent bits that are operated on as a unit.
Usually, a byte is a group of 8 adjacent bits and can store one character, i.e. 1-byte stores 1
character.
The Byte is the most commonly used unit of measuring the capacity of a computer memory.
A Word is a group of bits that the computer recognizes and executes (processes) at a time.
To represent characters, the bits are combined together. The group of bits representing characters
can also be described as Location.
In a Character machine, a location has 6 bits that represents a Byte, while the Byte machines has
8 bits making up a byte.
Character machines Byte machines.
6 bits = 1 byte 8 bits = 1 byte
12 bits = 2 bytes (½ Word) 16 bits =2 bytes (½ Word)
24 bits = 4 bytes (1 Word) 32 bits = 4 bytes (1 Word)
The memory capacity can be expressed as 32k, 64k, 256k, etc. The ‘K’ is a constant used to
represent the Kilobyte, which is made up of 1,024 bytes.
Another unit that can be used to measure the memory is Megabyte (MB). MB is used to denote
(stand for / represent / indicate) a million bytes, i.e. 1024 K is equivalent to 1MB.
Note. Half of a byte is described as a NIBBLE. A Nibble can be made up of 3 bits, for
Character machines and 4 bits for the Byte machines.
Exercise.
1. Data in a computer is represented in one major form. Define the term “Data representation”
in a computer system.
2. Define the following terms:
(i). Bit.
(ii). Byte.
(iii). Character.
(iv). Word.
3. Explain the term “NIBBLES” as used in data representation in computers.
CODING OF DATA.
A computer can understand only one language consisting of two symbols, 0 & 1(Binary digits).
Since the computer cannot understand data represented in human languages (i.e. numerals 0 - 9,
alphabets A – Z, and special symbols such as +, -, /, *, etc), it became necessary to change the
data to binary form, a process known as Coding of data.
In other words, to make communication possible between computers and human beings, data
must be coded in the form that can be understood by the computer and the information supplied
by a computer (after processing) must be coded in the form that can be understood by the user.
The coding and decoding of data in a computer is done by the Input/Output devices.
Codes used in Computer systems.
Human readable
Human Computer works -OR-
message Input Code converted to in CPU Code CPU Code converted Machine readable
Computer Code by Input devices to Output Code by Code
2
Data Representation
Output devices
Data representation – The representation of normal data in some type of coded form, such as
BCD, ASCII or EBCDIC.
NUMBER SYSTEMS.
The design and organization of a computer depends on the number system. The 4 number
systems are:-
1. Binary number system (Base 2).
2. Octal number system (Base 8).
3. Decimal number system (Base 10).
4. Hexadecimal number system (Base 16).
Binary numbers are numbers to base 2, and use only two digits; 0 & 1.
Octal numbers, are numbers to base 8, and consists 8 digits (0 to 7).
The decimal number system consists of 10 digits, 0 to 9.
Hexadecimal numbers are numbers to base 16 and there must be 16 digits. The sixteen symbols
used in the Hexadecimal system are; digits 0 to 9 & alphabets A to F.
Data Representation
The value of each digit in a number depends on the following:
(i). The digit itself, i.e. the face value of the digit.
(ii). The base of the number system.
(iii). The position of the digit in the number.
Example,
Let us consider the number 8888. All the digits represent the same value of 8. However, the
positional values are the absolute values multiplied by 10 raised to the positional power.
10 10 10 10
3 2 1 0
8 8 8 8
= (8x10 ) + (8x10 ) + (8x101) + (8x100)
3 2
5 6 2 1
= (5x103) + (6x102) + (2x101) + (1x100)
= (5x1000) + (6x100) + (2x10) + (1x1)
= 5000 + 600 + 20 + 1
= 5621
Note. In the Decimal system, the position value of each digit in a number increases 10 times as
we move from right to left starting with the rightmost digit.
Example 2: Fractional numbers.
(i). 0.839
10 10- 10- 10-
0 1 2 3
0 · 8 3 9
3 4 2 · 8 5
Data Representation
= (300 + 40 + 2) + (0.8 + 0.05)
= 342.85
It is clear that, the positional values of the numbers increase 2 times as we move from right to
left. This is because the base is 2.
Points.
Bit (Binary digit) – The digit 0 or 1 in the representation of a value in Binary notation.
Binary numbers are very important in the design, organization, and understanding of computers.
The Binary system is more convenient because the computer storage systems are based on a 2-
state principle (digits 1 & 0).
For example;
(i). Magnetic storage media use the magnetic principles to imitate the states of 1’s & 0’s.
A magnetized spot represents a 1, while the non-magnetized spot represents a 0.
(ii). The computer’s Internal memory uses magnetic polarity in one direction to represent a ‘1’
and in the reverse direction to represent a ‘0’.
(iii). The computer logical operations are also affected by pulse trains, where a pulse represents
a ‘1’ and no pulse represent a ‘0’.
In addition, the Binary code is used only for mathematical applications (it is not intended to
handle alphabetic data).
Data Representation
Exercise I.
1. State the FOUR types of Number systems.
2. Define and explain Decimal notation.
3. (a). What is the Binary system of numbers?
(b). Explain the main features of Binary notation.
(c). State one reason why computers use binary numbers.
4. Write out what A,B,C, and D represent in the table below.
Number System Values
A 0,1
B 0,1,2,3,4,5,6,7
C 0,1,2,3,4,5,6,7,8,9
D 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
A __________________________ B ______________________________
C __________________________ D ______________________________
5. (a). Explain the main characteristics of Octal notation.
(b). Explain the advantages of using Octal numbers over binary numbers.
6
Data Representation
6. Write a short note on Hexadecimal notation.
BASE CONVERSIONS.
Human beings normally work with the base 10 notation, i.e. all the data passed to go as computer
input is usually in decimal notation. Subsequently, the results of the computer operations are
communicated to the users in a form they can understand, i.e. in base 10 (decimal) notations.
The Base Conversion is therefore used to help computer users understand how data and
information is communicated between the computer and the user.
(i). FROM DECIMAL TO BINARY.
To convert a Decimal number (base 10) to a Binary number (base 2), the decimal number is
repeatedly divided by 2, until the number cannot be further divided by two. On each
division, the remainder is noted.
Then, the remainders are copied from the bottom Upwards to give the binary equivalent of
the decimal number.
Example 1: Convert a decimal no. such as 12110 to its binary equivalent.
2 121 REM
2 60 1
2 30 0
2 15 0
2 7 1 Copy
2 3 1
2 1 1
1 1
12110 11110012
Example 2: Convert the following decimal integers into their binary equivalents.
(i). 36
2 36 REM
2 18 0
2 9 0
2 4 1 Copy
2 2 0
2 1 0
1 1
12110 1001002
(ii). 247
2 247 REM
2 123 1
2 61 1
2 30 1
2 15 0 Copy
2 7 1
2 3 1
2 1 1
1 1
24710 111101112
Data Representation
Fractional numbers.
For a fractional number, the no. is divided into 2 parts; the whole number part & the
fraction part.
The whole no. is then converted to binary individually as shown above. The fraction part is
repetitively multiplied by 2, noting the complete units of two. This is done until the fraction
becomes a 0 or starts recurring.
The complete units of the fraction part are then copied downwards.
Example 1: Convert a decimal number such as 26.2510 to its binary equivalent.
2 26 REM Fractional part
2 13 0
2 6 1 0.25 x 2 = 0.50 0 Copy
2 3 0 Copy 0.50 x 2 = 1.00 1
2 1 1 0.00x2 (not necessary, hence stop)
1 1
0.25 0.01
2610 110102
1 0 1 1 0
=(1x24) + (0x23) + (1x22) + (1x21) + (0x20)
=16 + 0 + 4 + 2 + 0
Therefore, 101102 2210
Explanation:
Note that the binary number 10110 has 5 digits. Starting with the rightmost digit, the Most
Significant Digit (MSD) is in the 5th position. So, it is multiplied by 24 & each digit on its
right will be half of it in its positional value. The products obtained are added together to
get the required decimal equivalent.
Example 2: Convert the binary number 11110012 to its decimal equivalent.
2 2 2 2 2 2 2 Assign the powers to base 2.
6 5 4 3 2 1 0
1 1 1 1 0 0 1
= (1x26) + (1x25) + (1x24) + (1x23) + (0x22)
1 0
+ (0x2 ) + (1x2 )
Sum = 64 + 32 + 16 + 8 + 0+ 0 + 1
= 121
Therefore, 11110012 12110
Data Representation
Fractional numbers.
For a fractional number, the whole no. is converted to decimal as above.
The digits in the fraction part are divided by multiples of 2, starting from the decimal point.
Example 1: Convert a binary no. such as 11010.012 to its decimal equivalent.
2 2 2 2 2 2- 2- Weights.
4 3 2 1 0 1 2
1 1 0 1 0 . 0 1
= {(1x24) + (1x23) + (0x22) + (1x21)
0 -1 -2
+ (0x2 )}. {(0x2 ) + (1x2 )}
Sum = 16 + 8 + 0 + 2 + 0+ 0 + ¼
= 26 ¼
= 26.25
Therefore, 11010.012 26.2510
Points to Note.
(i). 2-11/21½
(ii). 5-21/521/25
(iii). 20 1 (any no. raised to the power of 0 is 1.)
Example 2: Express the following binary fractions to their decimal equivalents:-
(i). (0.111)2
2 2- 2- 2- Weights.
0 1 2 3
0 . 1 1 1
= (0x20). {(1x2-1) + (1x2-2) + (1x2-3)}
9
Data Representation
Sum =½+¼+⅛
= 0.5 + 0.25 + 0.125
Therefore, 0.1112 0.87510
(ii). (11011.101)2
2 2 2 2 2 2- 2- 2- . Weights.
4 3 2 1 0 1 2 3
1 1 0 1 1 . 1 0 1
= {(1x24) + (1x23) + (0x22) + (1x21) +
0 -1 -2 -3
(1x2 )}. {(1x2 ) + (0x2 ) + (1x2 )}
Sum = 16 + 8 + 0 + 2 + 1+ ½ + 0 + ⅛
= 27 + 0.5 + 0.125
Therefore, 11011.1012 27.62510
10
Data Representation
Fractional numbers.
To convert decimal fractions into their equivalent octal fractions, the whole part of the
decimal number is repeatedly divided by 8.
The fractional part is repetitively multiplied by 8, noting the complete units of 8, until the
fractional part becomes zero or up to the required number of digits. The complete units are
then copied downwards.
Example 1: Convert a decimal number such as 98.12510 to its octal equivalent.
8 98 REM Fractional part
8 12 2
8 1 4 Copy 0.125 x 8 = 1.00 1 Copy
1 1 0.00 x 8 (not necessary)
9810 1428 0.12510 0.18
1 2 6 3
= (1x83) + (2x82) + (6x81) + (3x80)
Sum = 512 + 128 + 48 + 3
= 691
Therefore, 12638 69110
11
Data Representation
6 0 5 7
= (6x83) + (0x82) + (5x81) + (7x80)
Sum = 3072 + 0 + 40 + 7
= 311910
8 8 Assign the powers to base 8.
1 0
4 2
= (4x81) + (2x80)
Sum = 32 + 2
= 3410
311910
x 3410
9357
12476
106046
Therefore, 60578 x 428 10604610
Fractional numbers.
For a fractional octal number, the whole part is converted to decimal as above. The digits in
the fraction part are divided by multiples of 8.
Example 1: Convert 142.18 to decimal.
8 8 8 8- Assign the powers to base 8
2 1 0 1
1 4 2 . 1
= {(1x82) + (4x81) + (2x80)}. (1x8-1)
Sum = 64 + 32 + 2 + 1/8
= 98 1/8
= 98.125
Therefore, 142.18 98.12510
12
Data Representation
13
Data Representation
7 A
= (7x161) + (Ax160)
Sum = 112 + 10
= 122
Therefore, 7A16 12210
Fractional numbers.
For a fractional hexadecimal value, the whole part is converted to decimal as above. The
digits in the fraction part are divided by multiples of 16.
Example 1: Convert 20.216 to decimal.
16 16 16- Assign the powers to base 16.
1 0 1
2 0 . 2
={(2x161) + (0x160)}. (2x16-1)
Sum =32 + 0 + (2x1/16)
= 32 + 1/8
= 32 1/8
=32.125
Therefore, 20.216 32.12510
Example 2: Convert the following hexadecimal fractions into their decimal equivalents.
(i). (0.8)H
(0.8)H = 8x16-1
= 8x (1/16)
= 0.5000
Therefore, (0.8)H = (0.5000)10
(ii). (A9.328)H
(A9.328)H = {Ax161 + 9x160} + {3x16-1 + 2x16-2 + 8x16-3}
= 10x16 + 9x1 + 3x(1/16) + 2x(1/256) + 8x(1/4096)
= 160 + 9 + 3x 0.0625 + 2x0.00390625 + 8x0.00024414
= 160 + 9 + 0.1875 + 0.0078125 + 0.001953125
= 169.197265625
Therefore, (A9.328)H = (169.197265625)10
(vii). FROM BINARY TO OCTAL.
Example1: Convert the binary number 100011100112 to Octal.
Solution.
The binary digits are grouped into 3’s and each group is used to represent an individual octal
digit.
21 22 21 21 20 Assign the powers to base 2.
0
2
0 1 0 0 0 1 1 1 0 0 1 141
Data Representation
NOTE. You can convert an Octal number to Binary, Hexadecimal to Binary or from Octal to
Hexadecimal.
To do this, first convert the given number to base 10 (decimal), then from base 10 to the required
base.
(ix). FROM OCTAL TO BINARY.
Example1: Convert 3478 to Binary.
Solution.
Step 1: First, convert the given number to base 10 (decimal).
8 8 8 Assign the powers to base 8.
2 1 0
3 4 7
= (3x82) + (4x81) + (7x80)
= (3x64) + (4x8) + (7x1)
= 192 + 32 + 7
= 23110.
Step 2: Then convert the resulting decimal number to the binary.
2 231 REM
2 115 1
2 57 1
2 28 1
2 14 0 Copy
2 7 0
2 3 1
2 1 1
1 1
15
Data Representation
23110 111001112
Therefore, 3478111001112
(x). FROM HEXADECIMAL TO BINARY.
Example 1: Convert 6DC16 to its binary equivalent.
Solution.
Step 1: Convert the hexadecimal (base 16) number given to its decimal (base 10)
equivalent.
6DC
= (6x162)+ (Dx161)+ (Cx160)
= 6x162 + 13x161 + 12x160
= 1536 + 208 + 12
= 175610.
Step 2: Convert the decimal (base 10) number obtained to binary (base 2).
2 1756 REM
2 878 0
2 439 0
2 219 1
2 109 1
2 54 1
2 27 0 Copy
2 13 1
2 6
1
2 3 0
2 1 1
1 1
Therefore, (6DC)16 (11011011100)2
Example 2: Convert A7116 to binary.
Solution.
Step 1: Convert the hexadecimal (base 16) number given to its decimal (base 10)
equivalent.
A71
= (Ax162)+ (7x161)+ (1x160)
= 10x162 + 7x161 + 1x160
= 2560 + 112 + 1
= 267310.
Step 2: Convert the decimal (base 10) number obtained to binary (base 2).
2 2673 REM
2 1336 1
2 668 0
2 334 0
2 167 0
2 83 1
2 41 1 Copy
2 20 1
2 10 0
2 5 0
2 2 16
2 1
1 Downloaded by ouko otieno ([email protected])
lOMoARcPSD|25790378
Data Representation
1
0
1
6 0 5 7
= (6x83) + (0x82) + (5x81) + (7x80)
Sum = 3072 + 0 + 40 + 7
= 3119
Therefore, 60578 311910
Step 2: Then convert the resulting decimal number to the Hexadecimal.
16 3119 REM
16 194 F (=15 in decimal)
12 2 Copy
12 C (=12 in decimal)
311910 C2F16
Therefore, 60578C2F16
Exercise I.
1. (A). What are Base Conversions?
(B). Explain the following conversions:
(i). From decimal to binary.
(ii). From binary to decimal.
(iii). From decimal to Octal.
(iv). From octal to decimal.
(v). From decimal to hexadecimal.
(vi). From hexadecimal to decimal.
2. Perform the following computer arithmetic. In each case, show how you arrive at your
answer.
(A). Convert the following decimal numbers to their binary equivalent.
(i). 11
(ii). 001
(iii). 255
(iv). 2346
(v). 322.6875 (3 marks).
(B). Convert the following binary numbers to decimal.
(i). 110111001 (2 marks)
(ii). 10101.1011 (2 marks)
(C). Convert the following binary numbers to hexadecimal number systems.
(i). 1011 (2 marks).
(ii). 11110101 (2 marks).
(iii). 10100000001111111
(iv). 110111.11 (2 marks).
17
Data Representation
(v). 1.1110101 (2 marks).
(vi). 0.10111010110011101111
Exercise II.
1. Convert the following to Hexadecimal.
(i). 24010 (2 marks).
(ii). 60578 (4 marks).
2. (A). Convert the following numbers to their Binary equivalents.
(i). 3768. (3 marks).
(ii). A6B16. (4 marks)
(B).Convert the following into binary:
(i). 3478.
(ii). 47310.
(iii). BCD16. (12 marks).
3. A. Convert the following numbers into their decimal equivalent showing all steps.
(i). 110101.01102
(ii). 3478
B. Convert the following numbers into their hexadecimal equivalent showing all steps
(i). 35610
(ii). 67548
4. Convert the following octal numbers to hexadecimal.
(i). 6057
(ii). 56752 (3 marks).
18
Data Representation
NEGATIVE NUMBERS.
Both positive and negative numbers can be represented in the computer memory during
processing.
The input numbers whether positive or negative are all represented in binary form.
The negative numbers are used to carry out subtraction in the computer’s arithmetic operations.
This is based on the fact that, subtracting a number is the same as adding its negative to the other.
The following are the various methods used to represent negative numbers in the computer:-
(i). One’s Complement (1C) method.
(ii). Two’s Complement (2C) method.
(iii). Signed Magnitude method.
19
Data Representation
+1710 0 100012
Exercise.
1. (a). What are Negative numbers?
(b). Explain the main methods of using negative numbers.
BINARY ARITHMETICS.
ADDITION:
Adding binary numbers is the same as adding decimal numbers. The difference is that, any
complete units of two’s are carried and added to the next significant digit.
Binary addition rules.
During binary addition (i.e. when adding two digits) the following rules need to be noted.
Sum Carry
0 + 0 = 0 0
0 + 1 = 1 0
1 + 0 = 1 0
1 + 1 = 0 1
Example 1:
1 0 0 1
+ 0 1 0 1
1 1 1 0
Example 2:
1 1 0 1 02
+ 1 0 1 02
20