0% found this document useful (0 votes)
2 views

Chapter 4 Data Representation

The document is a lecture note on data representation in computing, covering number systems such as decimal, binary, octal, and hexadecimal. It outlines objectives for students, including the ability to convert between these systems and perform basic arithmetic operations in binary. Additionally, it provides detailed explanations and examples for converting numbers between decimal and binary formats.

Uploaded by

amosopiyo994
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)
2 views

Chapter 4 Data Representation

The document is a lecture note on data representation in computing, covering number systems such as decimal, binary, octal, and hexadecimal. It outlines objectives for students, including the ability to convert between these systems and perform basic arithmetic operations in binary. Additionally, it provides detailed explanations and examples for converting numbers between decimal and binary formats.

Uploaded by

amosopiyo994
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/ 18

School of Computing and Informatics

BIT 113 – Fundamental of Computing

R
Data Representation

Lecturer Contact (name, telephone, e-mail)


Name: Dr. Raphael Angulu

U
Cell Number: 0729 260 641
Email: rangulu@mmust.ac.ke

Introduction
UL
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
schemes. These are the techniques (systems) used by computers to represent data in memory.
G
Objectives
By the end of this topic, you should be able to
AN

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

2. Explain three commonly used computer coding schemes

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
DR

7. Perform subtraction and addition of binary numbers

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

Data Representation

R
3.1 Number Systems

U
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


UL
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.
G
Decimal counting goes:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, and so on.
AN

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

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.

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

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

R
= 200 + 50 + 8

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

U
= 25810

Am sure you still remember that any number n raised to power 0 is equal to 1. As in, n0 = 1. The powers
follow the same thing you learnt in class 2, do you remember ones, tens, hundreds, thousands etc? You can

UL
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
0.72510 = 7 × 10−1 + 2 × 10−2 + 8 × 10−3
G
1 1 1 1
=7× +2× 2 +5× 3 remember a−b =
101 10 10 ab
AN

7 2 5
= + +
10 100 1000

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

2 5 8 · 7 2 5
2 1 0 −1 −2 −3

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


Numbers are represented to the base of two (X2 ). This number system uses two digits to represent any
number. These digits are 0 and 1. The computer commonly use this number system to represent numbers
(as well as other characters).

R
Binary counting goes (read as zero, one, two, three. . . fifteen, sixteen)
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000 and so on

From the counting above, you can see to represent number 510 in binary is 1012 . How do we get the

U
next number after 1012 ? We just add 1 to 1012 and we get (six) which is 1102 . This is done as

101 [5 in decimal]
+1 [1 in decimal]

UL 110 [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
with 9 in decimal number system.
G
Just like in the decimal number system, every digit has a power. The digit in the far right (just before
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.
AN

1 0 1
2 1 0

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

2. Divide the quotient by 2 and keep the remainder

4 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2020: Data Representation Notes
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


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

R
Reading these remainders from down upwards, we find that 810 = 10002
2. Convert the decimal number 1110 to binary
11 ÷ 2 = 5 rem 1 → 1

U
5 ÷ 2 = 2 rem 1 → 1
2 ÷ 2 = 1 rem 0 → 0
1 ÷ 2 = 0 rem 1 → 1

UL
Reading these remainders from down upwards, we find that 1110 = 10112
3. Convert decimal number 2710 to binary
27 ÷ 2 = 13 rem 1 → 1
13 ÷ 2 = 6 rem 1 → 1
G
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
1. Multiply the number by 2 and keep the whole number. 0.25 × 2 = 0.50 so you pick 0
.
DR

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

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

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2020: Data Representation Notes 5
2. Convert the number 0.72510 to binary

0.725 × 2 = 1.450 → 1
0.450 × 2 = 0.900 → 0
0.900 × 2 = 1.800 → 1
0.800 × 2 = 1.600 → 1
0.600 × 2 = 1.200 → 1
0.200 × 2 = 0.400 → 0
0.400 × 2 = 0.800 → 0
0.800 × 2 = 1.600 → 1

R
This fraction is recurring, so we can stop there and say, 0.72510 = 0.101110012 by reading whole
numbers from up-downwards.

3. Convert the number 0.12510 to binary

U
0.125 × 2 = 0.250 → 0
0.250 × 2 = 0.500 → 0
0.500 × 2 = 1.000 → 1

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

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

Converting whole numbers from Binary to Decimal


G
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
AN

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

3. Add the multiplications in step 2 above

Examples

1. Convert 10112 to decimal

1 0 1 1
.

3 2 1 0
DR

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

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

6 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2020: Data Representation Notes
2. Convert 11100112 to decimal

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

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 )

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

R
= 64 + 32 + 16 + 0 + 0 + 2 + 1

= 11510

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

UL
Converting fractions numbers from Binary to Decimal
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


G
3. Add the multiplications in step 2 above

Examples
AN

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

= 0 × 2−1 + 0 × 2−2 + 1 × 2−3


.
DR

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

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

1
= = 0.12510
8

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2020: Data Representation Notes 7
2. Convert 0.101110012 to decimal

0 · 1 0 1 1 1 0 0 1
−1 −2 −3 −4 −5 −6 −7 −8

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

= (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
= 1× 1 + 0× 2 + 1× 3 + 1× 4 + 1× 5 + 0× 6 + 0× 7 + 1× 8

R
2 2 2 2 2 2 2 2

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

U
1 1 1 1 1
= + 0 + + + + 0 + 0 +
2 8 16 32 256

Exercise
= 0.7226562510
UL
Convert the following fractions to decimal: 0.110012 , 0.1102 , 0.01012
G
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.
AN

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

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
DR

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

= (1 × 81 ) + (0 × 80 )

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

= 810

and 128 is equivalent to 1010 as shown in Figure 3.9

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

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

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

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

=8+2

R
= 1010

Converting from decimal to octal


To convert a number from decimal to octal

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

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

UL
3. Repeat step 2 above until the quotient becomes 0

4. Read the remainders from down upwards

Example

1. Convert the number 1010 to octal


G
10 ÷ 8 = 1 rem 2 → 2
1 ÷ 8 = 0 rem 1 → 1
AN

Reading the remainders from down upwards we get 1010 = 128

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
DR

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

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

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2020: Data Representation Notes 9
Examples

1. Convert 2468 to decimal

2 4 6
2 1 0

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

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

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

= 128 + 32 + 6

U
= 16610

2. Convert 1578 to decimal

UL 1
2
5
1
8
0

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

= (1 × 82 ) + (5 × 81 ) + (8 × 80 )
G
= (1 × 64) + (5 × 8) + (8 × 1)
AN

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

Converting from binary to octal


To convert from binary to octal

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)

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

10 Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2020: 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

Example

1. Convert the number 111001012 to octal

= 011 100 101


= 3 4 6

R
= 3468

2. Convert the number 10010111001112 to octal

= 001 001 011 100 111

U
= 1 1 3 4 7
= 113478

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

Converting from octal to binary


To convert from octal to binary
G
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


AN

Examples

1. Convert 3468 to binary

= 3 4 6
= 011 100 110
= 0111001102
.

2. Convert 24538 to binary


DR

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

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

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

Dr. Raphael Angulu, BIT 113 SCI, MMUST, 2020: Data Representation Notes 11
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
with respective alphabet between A and F)

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.

R
Example

1. Convert the number 4310 to hexadecimal

43 ÷ 16 = 2 rem 11(B) → B
2 ÷ 16 = 0 rem 2 → 2

U
Reading the remainders from down upwards, 4310 = 2B16

2. Convert 23410 to hexadecimal

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


14 ÷ 16 = 0 rem 14(E) → E

Reading remainders from down upwards, we get that 23410 = EA16

Exercise
G
Convert the following numbers to hexadecimal: 5610 , 43510 , 2410

Converting from hexadecimal to decimal


AN

To convert from hexadecimal to decimal

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
DR

1. Convert 2016 to decimal

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, 2020: 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 )
= (14 × 161 ) + (10 × 160 )
= (14 × 16) + (10 × 1)

R
= 224 + 10
= 23410

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

U
Converting from binary to hexadecimal

UL
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
G
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Hexa 0 1 2 3 4 5 6 7 8 9 A B C D E F

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

3. Join the digits to form a hexadecimal number

Examples

1. Convert 1011011110112 to hexadecimal


.

= 1011 0111 1011


DR

= B 7 B
= B7B16

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

1. Convert B7B16 to binary

= B 7 B

R
= 1011 0111 1011
= 1011011110112

2. Convert A4F16 to binary

U
= A 4 F
= 1010 0100 1111
= 1010010011112

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

3.2 Binary Arithmetic


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

3.2.1 Binary Addition


AN

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

1. Add 101 + 11

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

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

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, 2020: 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
This follows the same approach as subtraction in decimal number system. Important point to remember is,
When we borrow from a right digit to the left digit, we borrow 2 (the base).

R
Wait, you did the following subtraction in primary school

42
+ 15

U
27

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
that 1 + 2 6= 12 but 10 + 2 = 12.
UL
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.

To perform the above subtraction in binary we do 101010 − 1111 which is


G
101010 [42 in decimal]
− 1111 [15 in decimal]
AN

11011 [27 in decimal]

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


.
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, 2020: 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
Examples
1. Perform 1000 - 11

R
1000 [8 in decimal]
− 11 [3 in decimal]

U
Ensure subtrahend has same bits with minuend. Subtrahend becomes 0011
1’s compliment of subtrahend 1100

UL
2’s compliment of subtrahend

Add 2’s compliment of subtrahend to minuend

1000
+ 1101
1100 + 1 = 1101

[8 in decimal]
[-3 in decimal]
0101 [5 in decimal]
G
2. Perform 1100 - 111
AN

1100 [12 in decimal]


− 111 [7 in decimal]

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


DR

1100 [12 in decimal]


+ 1001 [-7 in decimal]
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, 2020: 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

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

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

3.3.2 Extended Binary Coded Decimal Information Code (EBCDIC)

U
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
was called EBCDIC (Extended Binary Coded Decimal Information Code).

UL
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
G
. AN

Figure 3.15: Portion of Original EBCDIC Table


DR

EBCDIC code for a particular character,

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, 2020: 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.

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

R
U
UL
G
. AN
DR

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy