You are on page 1of 18

School of Computing and Informatics

l
ae
BIT 113 – Fundamental of Computing
Data Representation

ph
Lecturer Contact (name, telephone, e-mail)
Name: Dr. Raphael Angulu
Cell Number: 0729 260 641
Email: rangulu@mmust.ac.ke

Introduction
Ra
In this topic, we will learn concepts of data representation. We will start by discussing various number
systems used by computers to represent numbers. This will be followed by a brief introduction to coding
u
schemes. These are the techniques (systems) used by computers to represent data in memory.
l
Objectives
gu

By the end of this topic, you should be able to

1. Explain decimal, octal, binary and hexadecimal number systems

2. Explain three commonly used computer coding schemes


An

3. Convert decimal numbers to binary

4. Convert binary numbers to decimal

5. Convert decimal numbers to octal and back from octal to decimal and binary

6. Convert decimal numbers to hexadecimal and back from hexadecimal to decimal, binary and octal

7. Perform subtraction and addition of binary numbers


.
Dr

Learning Activities
The learning activities (Exercise questions) are presented after every sub-topic
Chapter 3

l
Data Representation

ae
ph
3.1 Number Systems

There are infinite ways to represent a number. The four commonly associated with modern computers and
digital electronics are: decimal, binary, octal, and hexadecimal.

3.1.1 Decimal Number System Ra


Numbers are represented to the base of ten (X10 ). This number system uses a total of 10 (ten) digits to
represent any number. These digits are 0 through 9. Decimal number system (base 10) is the way most
human beings represent numbers, you have been using this number system from early years in primary.
u
Decimal counting goes:
l
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, and so on.
gu

You can see from above, to represent number 15 in decimal, we use a 1 and a 5 from the 10 digits used to
represent numbers in decimal, i.e 0 - 9.

Now, now do you represent two hundred and fifty eight in decimal number system? Sounds like a grade
An

four question, but it is very important as it will form a firm basis to understanding the other number systems.

The answer is straight forward, two hundred and fifty eight in decimal is represented as 25810 . Just as
you did in mathematics, the base is written as a subscript.

Now, read this number out loudly: 258. I hope you did not say Two Fifty Eight, that is wrong. The
correct way to read this number is Two hundred and fifty eight. This tells us that, the 2 in the number
.

represents 200, the 5 represents 50 and the 8 represents 8. That is why we read the 2 as two hundred,
the 5 as fifty and the 8 as eight.
Dr

You can see clearly that 200 + 50 + 8 = 258. Now lets look at the next concept.

Everything that has a base has a power. Decimal number system represents numbers to a base of 10.
What does this mean? This means, every digit in a decimal number has a base of 10 and a power. The
power of the digit corresponds to the position of the digit, with the right-most digit having a power of 0
and the powers increase as you move towards the left. For instance,

In our number 25810 , 8 has power 0, 5 has power 1 and 2 has power 2 as shown in Figure 3.1.

2 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes
2 5 8
2 1 0

Figure 3.1: Powers of each digit in a decimal number 25810

The base of these digits is the same, 10. Therefore, the number 25810 is actually representation of
25810 = 2 × 102 + 5 × 101 + 8 × 100

l
= 2 × 100 + 5 × 10 + 8 × 1

ae
= 200 + 50 + 8

ph
. . . thats why we read this number as ”two hundred and fifty eight. . . ” and write it as

= 25810

Am sure you still remember that any number n raised to power 0 is equal to 1. As in, n0 = 1. The powers

Ra
follow the same thing you learnt in class 2, do you remember ones, tens, hundreds, thousands etc? You can
see we also start from right-left when assigning power to whole decimal numbers.

For fractional decimal numbers, we assign powers to the digits from left-to-right starting with the first
digit after the decimal point taking power -1. For example, a fraction like 0.72510 , 7 will have power -1, 2
will have power -2 while 5 will have power -3. This fraction is actually represented as
u
0.72510 = 7 × 10−1 + 2 × 10−2 + 8 × 10−3
l
1 1 1 1
=7× +2× 2 +5× 3 remember a−b =
gu

101 10 10 ab

7 2 5
= + +
10 100 1000
An

= 0.7 + 0.02 + 0.005

= 0.72510
Putting these two numbers together, the number 258.72510 will look as shown in Figure 3.2.

2 5 8 · 7 2 5
.

2 1 0 −1 −2 −3
Dr

Figure 3.2: Powers of each digit in a decimal number 258.72510

Do you notice the powers look like reversed number line we did in form one? Positives are on the left,
negatives on the right.

Lets go back to counting in decimal number system. We count as


0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 . . . 18, 19, 20, 21,. . . 28, 29, 30, 31, . . . 38, 39, 40, 41, . . . 48, 49, 50 and so on

Do you notice something with this counting? You must have noticed two things

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes 3
• That, to get the next number, we add one to the current number

• That, when you add one to the highest number in the set (for this case 9), you get 0 carry 1. Just
as you did in class 1 a decade or so ago. This is how we move from 9 to 10, from 19 to 20, from 29
to 30, from 39 to 40 etc. The same concept applies to other number systems as we will see
shortly

3.1.2 Binary Number System

l
Numbers are represented to the base of two (X2 ). This number system uses two digits to represent any

ae
number. These digits are 0 and 1. The computer commonly use this number system to represent numbers
(as well as other characters).

Binary counting goes

ph
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000 and so on
(read as zero, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

From the counting above, you can see to represent number 510 in binary is 1012 . How do we get the
next number after 1012 ? We just add 1 to 1012 and we get (six) which is 1102 . This is done as

101
+1
110
Ra
[5 in decimal]
[1 in decimal]
[6 in decimal]

You can notice from this example that, when we add 1 to 1 in binary, we get 0 carry 1. Remember, 1 is
the highest digit in the set 0, 1 used by binary number systems to represent numbers. Same thing we saw
u
with 9 in decimal number system.
l
Just like in the decimal number system, every digit has a power. The digit in the far right (just before
gu

the dot in the case of fractional parts) has a power of 0 and the powers increase towards the left. In binary,
the number five is represented as shown in Figure 3.3.

1 0 1
2 1 0
An

Figure 3.3: Powers of each digit in a binary number 1012

The base of each digit is 2. Therefore, number five in binary is actually a representation of

1012 = 1 × 22 + 0 × 21 + 1 × 20

=1×4+0×2+1×1 remember n0 = 1
.
Dr

=4+0+1 remember n×0=0

= 510

Converting whole numbers from Decimal to Binary


To convert a whole number from decimal to binary

1. Divide the number by 2 and keep the remainder. 5 ÷ 2 = 2 rem 1

4 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes
2. Divide the quotient by 2 and keep the remainder

3. Repeat step 2 above until the remainder is 0 (Remainder will only be 0 if quotient is less than 2)

4. Read the remainders from down upwards.

Examples

1. Convert the decimal number 810 to binary

l
ae
8 ÷ 2 = 4 rem 0 → 0
4 ÷ 2 = 2 rem 0 → 0
2 ÷ 2 = 1 rem 0 → 0

ph
1 ÷ 2 = 0 rem 1 → 1

Reading these remainders from down upwards, we find that 810 = 10002

2. Convert the decimal number 1110 to binary

Ra
11 ÷ 2 = 5 rem 1 → 1
5 ÷ 2 = 2 rem 1 → 1
2 ÷ 2 = 1 rem 0 → 0
1 ÷ 2 = 0 rem 1 → 1

Reading these remainders from down upwards, we find that 1110 = 10112
u
3. Convert decimal number 2710 to binary
l
27 ÷ 2 = 13 rem 1 → 1
gu

13 ÷ 2 = 6 rem 1 → 1
6 ÷ 2 = 3 rem 0 → 0
3 ÷ 2 = 1 rem 1 → 1
1 ÷ 2 = 0 rem 1 → 1
An

Reading these remainders from down upwards, we find that 2710 = 110112

Exercise
Convert the following numbers from decimal to binary: 45, 189, 23, 87, 64

Converting Fractions from decimal to binary


.

To convert a fractional number from decimal to binary


Dr

1. Multiply the number by 2 and keep the whole number. 0.25 × 2 = 0.50 so you pick 0

2. Multiply the resulting fractional part by 2 and keep the whole number 0.50 × 2 = 1.00 so you pick 1.

3. Repeat step 2 above until the fractional part becomes 0 (or until you reach satisfactory accuracy)

4. Read the whole numbers from up downwards.

Example

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes 5
1. Convert the 0.2510 to binary

0.25 × 2 = 0.50 → 0
0.50 × 2 = 1.00 → 1

Reading the whole numbers from up-downwards we get 0.2510 = 0.012

2. Convert the number 0.72510 to binary

l
0.725 × 2 = 1.450 → 1

ae
0.450 × 2 = 0.900 → 0
0.900 × 2 = 1.800 → 1
0.800 × 2 = 1.600 → 1

ph
0.600 × 2 = 1.200 → 1
0.200 × 2 = 0.400 → 0
0.400 × 2 = 0.800 → 0
0.800 × 2 = 1.600 → 1

numbers from up-downwards.

3. Convert the number 0.12510 to binary


Ra
This fraction is recurring, so we can stop there and say, 0.72510 = 0.101110012 by reading whole

0.125 × 2 = 0.250 → 0
u
0.250 × 2 = 0.500 → 0
0.500 × 2 = 1.000 → 1
l

Reading whole numbers from up-downwards we get 0.12510 = 0.0012


gu

Exercise
Convert the following numbers from decimal to binary: 0.62510 , 0.712510 , 0.812510 , 82.42510
An

Converting whole numbers from Binary to Decimal

To convert whole numbers from binary to decimal

1. Starting from the rightmost digit, assign powers to each digit, with the rightmost digit having power
0

2. Multiply each digit by 2 raised to the digits’ power


.
Dr

3. Add the multiplications in step 2 above

Examples

1. Convert 10112 to decimal

1 0 1 1
3 2 1 0

Figure 3.4: Powers of each digit in a binary number 10112

6 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes
= (1 × 23 ) + (0 × 22 ) + (1 × 21 ) + (1 × 20 )

= (1 × 8) + (0 × 4) + (1 × 2) + (1 × 1)

=8+0+2+1 remember n×0=0

= 1110

l
ae
2. Convert 11100112 to decimal

1 1 1 0 0 1 1
6 5 4 3 2 1 0

ph
Figure 3.5: Powers of each digit in a binary number 11100112

= (1 × 26 ) + (1 × 25 ) + (1 × 24 ) + (0 × 23 ) + (0 × 22 ) + (1 × 21 ) + (1 × 20 )

Ra
= (1 × 64) + (1 × 32) + (1 × 16) + (0 × 8) + (0 × 4) + (1 × 2) + (1 × 1)

= 64 + 32 + 16 + 0 + 0 + 2 + 1
u
= 11510
l
Exercise
gu

Convert the following numbers to decimal: 1011111012 , 101112 , 100001112

Converting fractions numbers from Binary to Decimal


An

To convert fractions from binary to decimal

1. Starting with first digit after the decimal point (dot), assign powers as you move to the right, with
first digit after decimal point having power -1.

2. Multiply each digit by 2 raised to digits power


.

3. Add the multiplications in step 2 above


Dr

Examples

1. Convert 0.0012 to decimal

0 · 0 0 1
−1 −2 −3

Figure 3.6: Powers of each digit in a binary number 0.0012

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes 7
= 0 × 2−1 + 0 × 2−2 + 1 × 2−3

1 1 1 1
=0× +0× 2 +1× 3 remember a−b =
21 2 2 ab

1 1 1
=0× +0× +1×
2 4 8

l
1
= = 0.12510

ae
8

2. Convert 0.101110012 to decimal

0 · 1 0 1 1 1 0 0 1

ph
−1 −2 −3 −4 −5 −6 −7 −8

Figure 3.7: Powers of each digit in a binary number 0.0012

1
 

2
1
 

2
1
 

2
1
 

2
1
 

2
1
 

2
1
 

2
1
= 1× 1 + 0× 2 + 1× 3 + 1× 4 + 1× 5 + 0× 6 + 0× 7 + 1× 8
2

Ra
= (1 × 2−1 ) + (0 × 2−2 ) + (1 × 2−3 ) + (1 × 2−4 ) + (1 × 2−5 ) + (0 × 2−6 ) + (0 × 2−7 ) + (1 × 2−8 )

               
1 1 1 1 1 1 1 1
u
= 1× + 0× + 1× + 1× + 1× + 0× + 0× + 1×
2 4 8 16 32 64 128 256
l
1 1 1 1 1
= + 0 + + + + 0 + 0 +
gu

2 8 16 32 256

= 0.7226562510
An

Exercise
Convert the following fractions to decimal: 0.110012 , 0.1102 , 0.01012

3.1.3 Octal Number System


This is a base 8 number system. It uses 8 digits to represent any number. These digits are 0 t0 7.

Counting in octal goes


.

0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 25, 26, 27, 30 and so on
Dr

Remember, when you add one to the highest number in the set (for this case 7), you get 0 carry 1.

Every digit in an octal number has a base of 8 and a power that corresponds to the digits position. For
example, in the counting above 108 = 810 . Lets prove this.

1 0
1 0

Figure 3.8: Powers of each digit in a octal number 108

8 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes
= (1 × 81 ) + (0 × 80 )

= (1 × 8) + (0 × 1)

= 810

and 128 is equivalent to 1010 as shown in Figure 3.9

l
1 2

ae
1 0

Figure 3.9: Powers of each digit in a octal number 128

ph
= (1 × 81 ) + (2 × 80 )

= (1 × 8) + (2 × 1)

Converting from decimal to octal


=8+2

= 1010 Ra
u
To convert a number from decimal to octal

1. Divide the number by 8 and keep the remainder. 10 ÷ 8 = 1 rem 2


l
gu

2. Divide the quotient by 8 and keep the remainder 1 ÷ 8 = 0 rem 1

3. Repeat step 2 above until the quotient becomes 0

4. Read the remainders from down upwards


An

Example

1. Convert the number 1010 to octal

10 ÷ 8 = 1 rem 2 → 2
1 ÷ 8 = 0 rem 1 → 1
.

Reading the remainders from down upwards we get 1010 = 128


Dr

2. Convert 1910 to octal

19 ÷ 8 = 2 rem 3 → 3
2 ÷ 8 = 0 rem 2 → 2

Reading the remainders from down upwards we get 1910 = 238

Exercise
Convert the following numbers to octal: 6710 , 12310 and 24510

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes 9
Converting from octal to decimal

To convert from octal to decimal

1. Starting with the rightmost digit, assign powers, with the rightmost digit taking power 0

2. Multiply each digit by 8 raised to digits power

3. Add the multiplications in step 2 above

l
ae
Examples

1. Convert 2468 to decimal

ph
2 4 6
2 1 0

Figure 3.10: Powers of each digit in a octal number 2468

Ra
= (2 × 82 ) + (4 × 81 ) + (6 × 80 )

= (2 × 64) + (4 × 8) + (6 × 1)

= 128 + 32 + 6
u
= 16610
l
gu

2. Convert 1578 to decimal

1 5 8
2 1 0
An

Figure 3.11: Powers of each digit in a octal number 1588

= (1 × 82 ) + (5 × 81 ) + (8 × 80 )

= (1 × 64) + (5 × 8) + (8 × 1)
.
Dr

= 64 + 40 + 8

= 11210

Exercise
Convert the following numbers to decimal: 3458 , 7418 and 2148

NOTE: Converting fractional numbers from decimal to octal and vice versa follows the same procedure as
in binary.

10 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes
Binary 000 001 010 011 100 101 110 111
Octal 0 1 2 3 4 5 6 7

Table 3.1: Lookup Table for Converting from binary to octal and octal to binary

Converting from binary to octal


To convert from binary to octal

l
1. Starting with the least significant digit (rightmost digit), group the binary digits into sets of three
(put leading zeros if last group has less than three bits)

ae
2. For each set, assign the octal digit from the lookup table shown in Table 3.1
3. Join the octal digits to form the octal representation of a binary number

ph
Example
1. Convert the number 111001012 to octal
= 011 100 101

2. Convert the number 10010111001112 to octal


= 001
= 3
= 3468

001
Ra
4

011
6

100 111
= 1 1 3 4 7
u
= 113478

Exercise
l

Convert the following numbers to octal: 1001001111012 , 101111012 and 10111012


gu

Converting from octal to binary


To convert from octal to binary
An

1. Check the lookup table in Table 3.1, assign corresponding three bit set for each octal digit
2. Join the sets to form a binary number
Examples
1. Convert 3468 to binary
= 3 4 6
.

= 011 100 110


Dr

= 0111001102

2. Convert 24538 to binary


= 2 4 5 3
= 010 100 101 011
= 0101001010112

Exercise
Convert the following numbers to binary: 34768 , 21348 and 6528

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes 11
3.1.4 Hexadecimal Number System
It uses 16 digits to represent numbers. These digits are 0 - 9 and A - F. In hexadecimal, A represents 10,
B represents 11 and so on until F represents 15

Converting from decimal to hexadecimal


To convert from decimal to hexadecimal
1. Divide the number by 16 and keep the remainder (If the remainder is between 10 and 15, replace it

l
with respective alphabet between A and F)

ae
2. Divide the quotient by 16 and keep the remainder
3. Repeat step 2 above until the quotient is 0
4. Read the remainders from down upwards.

ph
Example
1. Convert the number 4310 to hexadecimal
43 ÷ 16 = 2 rem 11(B) → B

Reading the remainders from down upwards, 4310 = 2B16


2. Convert 23410 to hexadecimal
Ra
2 ÷ 16 = 0 rem 2 → 2

234 ÷ 16 = 14 rem 10(A) → A


14 ÷ 16 = 0 rem 14(E) → E
u
Reading remainders from down upwards, we get that 23410 = EA16
l
Exercise
Convert the following numbers to hexadecimal: 5610 , 43510 , 2410
gu

Converting from hexadecimal to decimal


To convert from hexadecimal to decimal
An

1. Starting with the rightmost digit, assign each digit a power with the rightmost digit having power 0
2. Multiply each digit by 16 raised to the digits power. If the hexa symbol is an alphabet, replace it with
corresponding value between 10 and 15
3. Add the multiplications above
Examples
1. Convert 2016 to decimal
.
Dr

2 0
1 0

Figure 3.12: Powers of each digit in a hexadecimal number 2016

= (2 × 161 ) + (0 × 160 )

= (2 × 16) + (0 × 1)
= 3210

12 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes
E(14) A(10)
1 0

Figure 3.13: Powers of each digit in a hexadecimal number EA16

2. Convert EA16 to decimal

= (E × 161 ) + (A × 160 )

l
= (14 × 161 ) + (10 × 160 )

ae
= (14 × 16) + (10 × 1)
= 224 + 10
= 23410

ph
Exercise
Convert the following numbers to decimal: A8B16 , 3CD16 and 4F B16

Ra
Converting from binary to hexadecimal

To convert from binary to hexadecimal

1. Starting from the rightmost digit, group the binary digits in sets of 4 bits (add leading zeros if last set
has less than 4 bits)

2. Check the corresponding hexadecimal digit in the lookup table shown in Table 3.2
u
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
l
Hexa 0 1 2 3 4 5 6 7 8 9 A B C D E F
gu

Table 3.2: Lookup Table for Converting from binary to hexadecimal and hexadecimal to binary

3. Join the digits to form a hexadecimal number


An

Examples

1. Convert 1011011110112 to hexadecimal

= 1011 0111 1011


= B 7 B
.

= B7B16
Dr

2. Convert 1101011011111112 to hexadecimal

= 0110 1011 0111 1111


= 6 B 7 F
= 6B7F16

Exercise
Convert the following numbers to hexadecimal: 101112 , 111110111102 and 1011011111012

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes 13
Converting from hexadecimal to binary
To convert from hexadecimal to binary

1. For each hexadecimal digit, look for corresponding 4 digit binary in the lookup table in Table 3.2.

2. Join the sets of 4 bit binary to form hexadecimal number

Examples

l
1. Convert B7B16 to binary

ae
= B 7 B
= 1011 0111 1011
= 1011011110112

ph
2. Convert A4F16 to binary

= A 4 F
= 1010 0100 1111

Exercise
Ra
= 1010010011112

Convert the following numbers to binary: ABCD16 , D9C16 and 45616

3.2 Binary Arithmetic


u
In this section, we are going to demonstrate how to perform some basic binary arithmetic like addition and
subtraction
l
gu

3.2.1 Binary Addition


When adding binary numbers, always ensure the digits are right-aligned. Remember, 1 + 1 in binary is equal
to 0 carry 1. A carried bit is added to the next bit on the left. Lets look at examples
An

1. Add 101 + 11

0101 [5 in decimal]
+ 0011 [3 in decimal]
1000 [8 in decimal]

We added the right-most digits (1 + 1) and we got 0 carry 1. We added the carried bit to the next
left bit and added 1 + 0 + 1 and got 0 carry 1. The carried bit is added to the next left bit 1 + 1 and
.

get 0 carry 1. The carry is added to the left bit and we get 1. So, 101 + 11 = 1000
Dr

2. Add 11010 + 1100

011010 [26 in decimal]


+ 001100 [12 in decimal]
100110 [38 in decimal]

Exercise
Perform the following binary arithmetic: 10111001112 + 100012 and 100111102 + 101101111012

14 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes
3.2.2 Binary subtraction
There are two ways we can subtract binary numbers

1. Direct subtraction - Subtract smaller number from larger number

2. Using 2’s compliments

Direct Subtraction

l
This follows the same approach as subtraction in decimal number system. Important point to remember is,

ae
When we borrow from a right digit to the left digit, we borrow 2 (the base).

Wait, you did the following subtraction in primary school

ph
42
+ 15
27

that 1 + 2 6= 12 but 10 + 2 = 12.


Ra
Your mathematics teacher in primary must have told you to solve this, since 2 - 5 is impossible, you borrow
1 from 4 add it to 2 to get 12 then you do 12 - 5 = 7. As much as you believed them, you did not notice

This tells you that, when you borrow from a most significant digit to a less significant digit, what you
are borrowing is the base. For decimal, we borrow 10 and for binary we borrow 2.
u
To perform the above subtraction in binary we do 101010 − 1111 which is

101010 [42 in decimal]


l

− 1111 [15 in decimal]


gu

11011 [27 in decimal]

I have tried to show how to do this by hand in Figure 3.14.


. An
Dr

Figure 3.14: Binary Subtraction with borrowing

Using 2’s compliment


Using 2’s compliment, perform the following steps

1. Ensure the minuend (the number from which another number is to subtracted) and the subtrahend
(number to be subtracted from another number) have same number of bits, add leading zeros where
necessary. For example (8 - 3), 1000 - 11 you need to make it look like 1000 - 0011

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes 15
2. Convert the subtrahend into 1’s compliment by flip-flopping the bits. (Change 0 to 1 and 1 to 0). 1’s
compliment of 1001101 is 0110010

3. Add 1 to the 1’s compliment to get the 2’s compliment. For 1’s compliment above, 2;s compliment is
0

4. Add the 2’compliment to the minuend (2’s compliment is the negative of the subtrahend)

5. The final answer should have same number of bits as the minuend (or subtrahend). Any overflow bit
is discarded

l
ae
Examples
1. Perform 1000 - 11

1000 [8 in decimal]

ph
− 11 [3 in decimal]

Ensure subtrahend has same bits with minuend. Subtrahend becomes 0011

Add 2’s compliment of subtrahend to minuend

1000
Ra
1’s compliment of subtrahend
2’s compliment of subtrahend
1100
1100 + 1 = 1101

[8 in decimal]
+ 1101 [-3 in decimal]
u
0101 [5 in decimal]
l
2. Perform 1100 - 111
gu

1100 [12 in decimal]


− 111 [7 in decimal]
An

Ensure subtrahend has same bits with minuend. Subtrahend becomes 0111
1’s compliment of subtrahend 1000
2’s compliment of subtrahend 1000 + 1 = 1001

Add 2’s compliment of subtrahend to minuend

1100 [12 in decimal]


.

+ 1001 [-7 in decimal]


Dr

0101 [5 in decimal]

Exercise
Using 2’s compliment, perform 100011100 − 1011111 and 1111011 − 1100001

3.3 Coding Schemes


Coding scheme is a system of representing data in a computer. There are three commonly used coding
schemes used in computers for data representation.

16 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes
3.3.1 Binary Coded Decimal (BCD)
Early mainframe computers in the 1950s were programmed using numeric codes, not text. As a result, the
first coding system used in these computers only needed to represent the ten digits in decimal number system.

The BCD(Binary Coded Decimal) system used 4 bits to represent numbers as shown in Table 3.3. Therefore,

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Decimal 0 1 2 3 4 5 6 7 8 9

l
ae
Table 3.3: Binary Coded Decimal (BCD) Data Representation codes

to represent the number 253, the computer would store 0010 0101 0011.

ph
3.3.2 Extended Binary Coded Decimal Information Code (EBCDIC)
In the early 1960s, computers were increasing in speed and storage capacity. It was now possible to program
these computers (and store data) in text format as well as number format. IBM developed an extension to
the BCD code which would be able to represent all English characters and punctuation marks. This code

Ra
was called EBCDIC (Extended Binary Coded Decimal Information Code).

EBCDIC used 8 bits to represent characters, therefore it can represent 28 = 256 possible symbols.

Figure 3.15 shows a portion of the original EBCDIC table. The grey areas represent non-printable con-
trol keys (Esc, Del, Backspace, etc.), as well as special characters used in data transmission To find the
l u
gu
An

Figure 3.15: Portion of Original EBCDIC Table


.

EBCDIC code for a particular character,


Dr

1. Locate the character in the table (for example, ”J”)

2. Write down the four ”Low Order” bits on the left side of the table directly across from the character
(for ”J”, they are 1101).

3. Write down the four ”High Order” bits at the top of the table, directly above the character (for ”J”,
they are 0001).

Therefore, the 8-bit EBCDIC code for an upper-case ”J” is 1101 0001.

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes 17
3.3.3 American Standard Code for Information Interchange (ASCII)
This is the most common format for text files in computers and on the Internet. In an ASCII file, each
alphabetic, numeric, or special character is represented with a 7-bit binary number (a string of seven 0s or
1s). 128 possible characters are defined.

UNIX and DOS-based operating systems use ASCII for text files. Windows NT and 2000 uses a newer
code, Unicode. IBM’s S/390 systems use a proprietary 8-bit code called EBCDIC. Conversion programs
allow different operating systems to change a file from one code to another.

l
ae
ASCII was developed by the American National Standards Institute (ANSI)

ph
Ra
l u
gu
. An
Dr

18 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2022: Data Representation Notes

You might also like