Computer Number Systems Workbook

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Module: Computer Number Systems and

Boolean Algebra
Computer Number Systems
We all know and understand the decimal number system. Computers, on the other hand, make
use of the binary number system, where all data is stored in the computer as 0s and 1s. These 0s
and 1s can be stored as memory, where the size varies according to the kind of computer used
(microcomputers store 8 or 16 binary digits where large computers store as many as 128 binary
digits).

We usually don’t enter data using the binary number systems because it’s too time consuming
(too many 0s and 1s). Data is more likely entered into a computer by either the decimal, octal or
hexadecimal number systems. Octal and hexadecimal number systems are used most often
because they are more closely related to the binary system than is the decimal system.

We will use subscripts to denote the base we are working in. For example, the number 11 in the
binary system would be 112 , in the octal system 118 , in the decimal system 1110 (we will see
why it’s base 10 next). Let’s see how all these numbers are related.

Decimal and Binary Number Systems


Decimal Number System
First, let’s go back to the decimal number system. A number such as 7032 can be represented as
follows

(7 × 103 ) + (0 × 102 ) + (3 × 101 ) + (2 × 100 )


= 7000 + 0 + 30 + 7 = 7037

The 2 is in the ones position and the base 10 is raised to the power of 0; the 3 is in the 10s position
and the base 10 is raised to the power of 1; the 0 in the 100s position and the base 10 is raised
to the power of 2; the 7 in the 1000s position and the base 10 is raised to the power of 3. We can
take each digit in the number, and depending on its position, multiply it by a factor of base 10.
So, every number in the decimal number system can be written as numbers from 0 to 9 times
multiples of 10.
Module: Computer Number Systems and Boolean Algebra

Binary Number System


If we are working with the binary number system, we work with base 2 since there are only 2
digits (0s and 1s). The ones position has a power of 20 , the next position, the 2s position (similar
to the 10s position) is 21 , next, the 4s position (similar to the 100s position) is 22 and so on.

Converting Between Binary and Decimal Number Systems


Converting from Binary to Decimal Number Systems
Example: Convert the following binary numbers to decimal numbers.

a) 110102

b) 100011012

Converting from Decimal to Binary Number Systems


Example: Convert the following decimal numbers to binary numbers.

a) 1110 b) 3410

2
Module: Computer Number Systems and Boolean Algebra

Octal Number System


The octal number system, or base 8, has eight digits 0, 1, 2, 3, 4, 5, 6, 7. We work with this number
system the same way as decimal and binary, but with base 8.

Converting from Octal to Decimal Number Systems


Example: Convert the following octal numbers to decimal numbers.

a) 10258

b) 4328

Converting from Decimal to Octal Number Systems


Example: Convert the following decimal numbers to octal numbers.

a) 18910 b) 37610

3
Module: Computer Number Systems and Boolean Algebra

Hexadecimal Number System


Again, we convert the same way. The hexadecimal number system has a base of sixteen. In
working with remainders greater than 9, we substitute the characters 𝐴𝐴, 𝐵𝐵, 𝐶𝐶, 𝐷𝐷, 𝐸𝐸 and 𝐹𝐹 as
required.

Converting from Hexadecimal to Decimal Number Systems


Example: Convert the following hexadecimal numbers to decimal numbers.

a) 𝐶𝐶2916

b) 12𝐴𝐴𝐴𝐴16

Converting from Decimal to Hexadecimal Number Systems


Example: Convert the following decimal numbers to hexadecimal numbers.

a) 132410 b) 176310

4
Module: Computer Number Systems and Boolean Algebra

Binary to Octal to Hexadecimal to Decimal Conversion


Binary to Octal Conversions
Reminder: binary number system is base 2; octal number system is base 8.

Since many 0s and 1s are needed to represent larger numbers in the binary number system, when
we convert from binary to octal number systems, the number of digits required is reduced by a
factor of 3 (because one octal digit equals 3 bits). That is, all octal digits, 0 through 7, can be
represented by 3 bits.

0 = 000 4 = 100

1 = 001 5 = 101

2 = 010 6 = 110

3 = 011 7 = 111

Where do these come from? 1112 = (1 × 22 ) + (1 × 21 ) + (1 × 20 ) = 4 + 2 + 1 = 78

Example: Convert the following binary numbers to octal numbers.

a) 1101111000012 b) 1000.10112

Example: Convert the following octal numbers to binary numbers.

a) 4178 b) 3628

5
Module: Computer Number Systems and Boolean Algebra

Binary to Hexadecimal Conversions


To convert from a binary to a hexadecimal number, the number of digits required is reduced by
a factor of 4 because one hexadecimal digit equals 4 bits. That is, all hexadecimal digits, 0
through F, can be represented by 4 bits.

0 = 0000 8 = 1000

1 = 0001 9 = 1001

2 = 0010 𝐴𝐴 = 1010

3 = 0011 𝐵𝐵 = 1011

4 = 0100 𝐶𝐶 = 1100

5 = 0101 𝐷𝐷 = 1101

6 = 0110 𝐸𝐸 = 1110

7 = 0111 𝐹𝐹 = 1111

Where do these come from? 11112 = (1 × 23 ) + (1 × 22 ) + (1 × 21 ) + (1 × 20 ) = 8 + 4 +


2 + 1 = 1516 = 𝐹𝐹16

Example: Convert the following binary numbers to hexadecimal numbers.

a) 1101100110112 b) 1000.10112

Example: Convert the following hexadecimal numbers to binary numbers.

a) 𝐶𝐶0𝐷𝐷16 b) 𝐹𝐹2316

6
Module: Computer Number Systems and Boolean Algebra

Converting Between all the Systems


Example: Convert the following:

a) 20010 = _______________2 = _______________8 = _______________16

b) 𝐶𝐶2716 = _______________2 = _______________8 = _______________10

c) 738 = _______________16 = _______________2 = _______________10

7
Module: Computer Number Systems and Boolean Algebra

Adding and Subtracting in Binary, Octal and Hexadecimal


When adding numbers, they are added in columns; one number is placed below the other. We
then add each digit in the given column.

ADDITION
Adding Decimal Numbers
If we add the following decimal numbers 23 and 45, we have

23 + 45 =?

2 3

4 5

6 8

So 23 + 45 = 68.

If we add the following decimal numbers 64 and 87 in base 10, we have

carry 1 1
6 4
8 7
1 (15) (11)
(subtract value of carry/base) 10 10
1 5 1
We “subtract value of carry/base” since the numbers (15) and (11) are greater than 9 (since we
are using the decimal system of base 10).

So 6410 + 8710 = 15110 .

8
Module: Computer Number Systems and Boolean Algebra

Adding Octal Numbers


Example: Add the following octal numbers:

a) 7368 + 2158 b) 6048 + 7778

Adding Hexadecimal Numbers


Example: Add the following hexadecimal numbers:

a) 7𝐴𝐴𝐴𝐴16 + 57916 b) 𝐹𝐹34716 + 𝐸𝐸00616

9
Module: Computer Number Systems and Boolean Algebra

Adding Binary Numbers


Example: Add the following binary numbers:

a) 11012 + 10012 b) 1112 + 1012

SUBTRACTION
Subtracting Decimal Numbers
If we subtract the following decimal numbers 64 and 47, we have

borrowed 5
6 4
4 7
1 (-3)
(add value of carry/base) 10
1 7

We “add value of carry/base” since the numbers (-3) is less than 9 (since we are using the
decimal system of base 10).

So 6410 − 4710 = 1710 .

10
Module: Computer Number Systems and Boolean Algebra

Example: Subtract the following decimal numbers:


a) 4310 − 2510 b) 853410 − 674810

Subtracting Octal Numbers


Example: Subtract the following octal numbers:
a) 5128 − 2678 b) 21728 − 17178

11
Module: Computer Number Systems and Boolean Algebra

Subtracting Binary Numbers


Example: Subtract the following binary numbers:

a) 11102 − 01012 b) 10011 − 01101

Subtracting Hexadecimal Numbers


Example: Subtract the following hexadecimal numbers:

a) 𝐶𝐶3716 − 85𝐸𝐸16 b) 𝐹𝐹1𝐵𝐵216 − 𝐴𝐴𝐴𝐴𝐴𝐴716

12
Module: Computer Number Systems and Boolean Algebra

One’s to Two’s Complements


In order to simplify the design of the arithmetic section of a computer, subtraction is usually
performed by addition of the complement (of the number we are subtracting – called the
subtrahend).

One’s Complement
The one’s complement of a binary number is a way of allowing the computer to do an addition
of two binary numbers (using the complement method) instead of a subtraction. The
complement of a binary number is found by subtracting a binary number made up of all 1s by the
number at hand.

For example, the one’s complement of the binary number 10110010 is

1 1 1 1 1 1 1 1

1 0 1 1 0 0 1 0

0 1 0 0 1 1 0 1

Notice the one’s complement of a binary number is actually just changing the 0s to 1s and the
1s to 0s. Therefore, the one’s complement of 0111102 is 1000012 .

The computer is easily able to perform this “switch” by a circuit called an inverter.

Now, instead of subtracting, for example, 10110011 − 01101101, we would ADD 10110011
by the one’s complement of the second number 01101101.

Example: Find the difference between the following binary numbers using the one’s
complement method:

a) 10110011 − 01101101

b) 11011000 − 10110011

13
Module: Computer Number Systems and Boolean Algebra

Two’s Complement
It turns out that computers actually subtract by using the two’s complement method.

The two’s complement method is a way of bypassing the carry created by adding with the one’s
complement. To find the two’s complement of a binary number, we add 1 to the one’s
complement. For example, the one’s complement of 10011101 is 01100010. The two’s
complement adds that number to 1.

0 1 1 0 0 0 1 0

0 1 1 0 0 0 1 1

Therefore, the two’s complement of 10011101 is 01100011.

Example: Find the difference between the following binary numbers using the two’s
complement method:

a) 01100111 − 01001010

b) 01011011 − 00110110

14

You might also like