Data Representation
• Is concerned with how data (numeric or text) are represented in the computer.
• Data are represented in the computer as zeroes and ones, which is called
binary form/binary language/digital form.
• Therefore every data item entered into the computer for processing is
converted to this form, which is the computer’s language.
• In conclusion, the computer uses the base 2 number system to represent
data, both text or numeric.
The decimal/ denary number system
• Is commonly called the base 10 number system.
• It is made up of natural counting numbers we use daily in life.
• It is made up of ten symbols or values, which are 0,1,2,3,4,5,6,7,8,9.
The octal number system
• Is commonly called the base eight number system.
• It is made up of 8 symbols or values, which are 0,1,2,3,4,5,6,7.
The hexadecimal number system.
• Is commonly called the base 16 number system.
• It is made up of 16 values or symbols, which are 0,1,2,3,4,5,6,7,8,9, A,B, C, D,
E and F.
• Note that the values A to F replace the values 10 to 15.
• Also note that the maximum number or symbol in any base is always one less
than the base itself.
Conversion among bases
• It is possible to convert numerical data from one base to another.
Converting from decimal to any other base.
Technique
1. Repeatedly divide the decimal/denary number by the target base, jotting
down the quotient and the remainder.
2. When the quotient is zero, stop the division.
3. Read the remainder bottom up.
Example
• Convert the decimal number 250 to:
I. Binary
II. Octal
III. Hexadecimal.
Converting from any other base to decimal
Technique
1. Multiply each bit by its weight.
2. Add the results together.
NB: weights are powers of the base, and they increase from zero, starting from
the right most bit in the number going to the left.
Examples
• Perform the following conversions:
a. 100011102 to decimal
b. 7248 to decimal.
c. ABC16 to decimal
Binary to octal conversion
Technique
1. Group the bits into threes from the right.
2. Convert each group of threes into octal using weights.
NB: do not add the results of the groups together.
Example
• Convert 1011010111 to octal.
•=1 011 010 111
•=1 3 2 7
• =13278
Binary to hexadecimal conversion
1. group the bits into fours from the right.
2. Convert each group of fours to hexadecimal using weights.
example:
Convert 001010111011 to hexadecimal.
0010 1011 1011
2 B B
Octal to binary conversion
• Convert each octal digit in the octal number to its three binary equivalent
representation.
• Example convert 7058 to binary.
• 7 0 5
• 111 000 101
•
• therefore 705 = 111 000 101 in binary.
Octal to hexadecimal conversion
• Use binary as intermediary.
Technique
1. Convert each octal digit into a three bit binary value.
2. Group the bits into fours from the right.
3. Convert each group of four to hexadecimal using weights.
Example
• Convert 10768 to hexadecimal.
1 0 7 6
001 000 111 110
0010 0011 1110
2 3 14
=23E16
Hexadecimal to octal conversion
• Use binary as intermediary.
• Example: convert 1F0C16 to octal.
• Answ: 17414
Conversion of fractions
• It is possible to convert fractions among bases, just like whole numbers.
Decimal fractions to binary
convert the whole number part to binary by repeated division as usual.
As for the fractional part:
1. Multiply it by 2.
2. Record the integer part if it exists, else record 0.
3. Repeat steps and 2 until the fractional part becomes 0.
Example 2
• Convert 0.625 to binary.
• ANS: 0.101
Example 1
• Convert 23,375 to binary.
• ANS:
• Convert 23 to binary by repeated division, we get 10111.
• As for the fractional part:
0.375 x 2 = 0.75 (record 0)
0.75 x2 = 1.50 (record 1)
0.5 x2 = 1.0 ( record 1)
Fractional part is now zero, so 23,375 = 10111.011
If the fractional part does not terminate (get to zero), indicate the terminating
digits by putting three dots on top of them.
Binary fractions to decimal
• Convert the whole number part using weights.
• Convert the fractional part using weights.
• Add the results together.
• NB: powers of 2 for the fractional part become negative from the binary point
going to the right.
Example 1
• Convert 10.1011 to decimal.
= (1x21) + (0x20) + (1x2-1) + (1x2-2) + (1x2-3) + ( 1x2-4) +
= 2+ 0+ 0.5 + 0+ 0+ 0.125+ 0.625
= 2.6875
Example 2
• Convert 110.101 to decimal
• ANS 6.625
Octal fractions to binary
• Write each octal digit using three bits .
• For example, convert 0.1238 to binary.
• 0. 1 2 3
0. 001 010 011
Therefore 0.123= 0.001 010 0112
Binary fractions to octal
• Group the fractional part into threes from the binary point to the right.
• Convert each group into its octal equivalent.
• Example Convert 0.01012
= 0. 010 1
= 0. 2 4
Binary fractions to hexadecimal
• Group the fractional part into fours from the binary point to the right.
• Convert each group into its hexadecimal equivalent.
• Example: convert 0. 010101 to hexadecimal.
• 0.0101 0100
• 0.5416
Hexadecimal fractions to binary
• Replace each hexadecimal digit with its four bit binary equivalent.
example convert 2.A7 to binary
= 0010.1010 0111
Hexadecimal to octal
• Replace each hex digit with its four bit binary equivalent.
• Regroup the bits into threes from the radix point.
• Convert each group into its octal equivalent.
• Example convert 2.A7 to octal.
• 2= 0010, A= 1010 and 7 = 0111.
• = 2.516 base 8
Written exercise
Decimal Binary Octal Hexadecimal
29.8
101.1101
3.07
C.82
Binary multiplication
• Is achieved by shifts to the left or right.
• Each time an answer is produced, shift it one step to the left or right and
append a zero at the end of the answer, until all multiplications are done.
• Finally the bits in each column of the answers are added together to get the
final answer.
• The first number in a multiplication is called the multiplicand and the last one
is the multiplier.
• NB: the multiplier works from either the rightmost bit or the left most bit.
Rules for binary multiplication
1. 1x0=0
2. 1x1=1
3. 0x1=0
4. 0x0=0
Example 1
1000 multiplicand
X 1001 multiplier
Example 2
• 11011
X 101
Multiplication of binary numbers with fractions
1. Ignore the binary points and multiply as whole numbers.
2. Count the total number of values after the binary point( in both multiplicand
and the multiplier combined) and correctly place the binary point in the
answer.
Example 1
1011.01
X 110.1
Example 2
11011.101
x101.111
Binary division
• Is done the same way as long division in denary.
1. Divide: divide the working portion of the dividend by the divisor.(the divisor
is the number dividing into the other, and the dividend is the number being
divided)
2. Multiply: multiply the quotient by the divisor.
3. Subtract: subtract the product from the working portion of the dividend.
4. Bring down: copy down the next digit of the dividend to form the new
working portion and continue with steps 1 to 4 until all the dividend has
been used.
Example 1
• Evaluate 11001/101
Example 2
• Evaluate 1011.11/11
solution
• If the divisor has a binary point, shift the binary point right until the divisor is an
integer, and shift the dividend by the same number of places.
Representation of Negative Numbers
• Negative numbers are mostly represented using the complement of number.
• Complement of numbers can be in 1’s complement or 2’s complement.
• The complement of a number behaves like the negative of the original number.
1’s Complement
• One’s complement of a binary number is obtained by simply converting 1s to
0s and 0s to 1s.
• For example, given the following four-bit binary number 1010, its 1’s
complement becomes 0101.
• The alternating of bits only applies to negative numbers, positive numbers do
not change.
• For example +6 = 000001102 -6 = 11111001
• Two’s complement of number is obtained by:
a) Positive numbers remain the same
b) b) Negative numbers: - Change the number to its 1’s complement. - Add 1
to the result and the number will be in 2’s complement
question
• Convert -63 and -94 into 2’s complement, 8 bit, binary numbers.
• Add -63 and -94 into 2’s complement
Converting From Binary Two's Complement To Denary
Signed and Unsigned Numbers
• A binary number may be positive or negative. In daily life we use symbols “+”
and “-” to represent positive and negative numbers, respectively. However,
binary numbers use 0 (for positive) and 1 (for negative) in the computer.
Sign and Magnitude representation
• The magnitude of a number is its natural value, regardless of the sign.
Thus the magnitude of -25 and +25 is 25 (not considering the sign in this
situation).
• In binary form, 25 = 11001.
• Thus using Sign and Magnitude representation:
• +25 = 0 11001
• -25 = 1 11001 What only differs is the sign bit, not the magnitude.
example
• Show how to represent -77 in sign and magnitude representation.
1. American Standard Code For Information
Interchange (ASCII)
• Over the years, different computer designers have used different sets of codes
to represent characters, which has resulted in great difficulties in transferring
information from one computer to the other.
• Nowadays, most personal computers use the ASCII code.
• It was developed by the American National Standards Institute (ANSI).
• It has become the most popular/common code used by computers to translate
text (letters, numbers and symbols) into a form that can be sent to and
understood by other computers and devices such as modems and printers.
• Originally, ASCII used 7 binary digits to represent a single character, and
was able to represent 27 (128)different combinations.
• It was later extended, and now uses an 8 bit code to represent a character,
thus is able to represent 256 characters.
• Because of this, ASCII 8 is commonly called the Extended ASCII.
• Each representation standard has a character set, which is the set of
symbols that can be recognized and represented in that particular
representation standard.
• The 256 character set for the ASCII is broken down as follows:
o codes 0-31 ( the first 32 characters) are used for simple communication
protocols, not characters. They are control (non printable) characters.
o Codes 48 to 57 represent numeric values 0 to 9.
o Codes 65 to 90 represent uppercase letters A to Z.
o Codes 97 to 122 stand for lowercase letters a to z.
o Codes 128 to 255 represent extended characters (accented characters).
[Link] Coded Decimal (BCD)
• Is also known as packet decimal.
• it is an encoding in decimal in which each digit is represented by its own 4 bit
binary code.
• It was used in the early decimal computers as well as the IBM system 360
series for business applications.
• Its character set is made up of only ten characters, which are the numbers 0 to
9 in four bit binary.
BCD character set
Decimal value BCD representation
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
• Numbers larger than 9, having two or more digits in the decimal system are
expressed digit by digit.
• For example the BCD representation of the number
1895= 1 8 9 5
0001 1000 1001 0101
• NB: the BCD representation of a number is not the same as its binary
representation.
• BCD is used to represent numbers that are not proper numbers like
barcode numbers.
Advantages of BCD
• It is easy to convert from BCD to decimal and vice versa.
• There is no rounding off numbers when computing fractional numbers, thus no
errors due to rounding off
• Used in businesses where significant digit needs to be retained
Disadvantages of BCD
More bits are required to represent a number than binary.
Calculations with BCD numbers are more complex than with pure binary
numbers.
For example try adding the BCD representations of 1 and 19:
• We get 0000 0001
+ 0001 1001
0001 1010
• the first digit ,1, is wrong and 1010 is an invalid code in BCD. So whenever a
result is above 9, a six has to be added to the answer.
• If we add 0110 to 1010 we get 0010 000 which is 20 and correct.
questions
• Write down the BCD representation of 2906.
• Translate the BCD number 0110 0111 1001 0011 into denary.
3. Extended Binary Coded Decimal Interchange code
(EBCDIC)
• The Extended Binary Coded Decimal Interchange Code (EBCDIC) uses 8 bits
(4 bits for zone, 4 bits for digit) to represent a symbol in the data.
• EBCDIC allows 256 combinations of bits.
• 256 unique symbols are represented using EBCDIC code.
It represents decimal numbers (0 to 9), lower case letters (a-z), uppercase
letters (A-Z), Special characters, and Control characters (printable and non-
printable e.g. for cursor movement, printer vertical spacing etc.).
• EBCDIC codes are used, mainly, in the mainframe computers.
4. UNICODE
• Unicode is a universal character encoding standard for the representation of
text which includes letters, numbers and symbols in multi-lingual
environments.
• This is an international 16-bit data coding method which represents 65536
different characters.
• It is enough to represent characters in any language, even Chinese and
hieroglyphics.
Data Representation by Justin Tagwireyi is licensed under a Creative Commons Attribution-NonCommercial
4.0 International License.