0% found this document useful (0 votes)
25 views9 pages

Number Systems

This document discusses different number systems used in computing, including binary, octal, and hexadecimal. It provides instructions on how to convert between decimal, binary, octal, and hexadecimal numbers. The key points are: - Binary numbers use only the digits 0 and 1 and have a base of 2. Octal uses digits 0-7 and has a base of 8. Hexadecimal uses digits 0-9 and A-F and has a base of 16. - To convert a binary number to decimal, you write it as a sum of terms with coefficients that are powers of 2. - To convert a decimal number to binary, you repeatedly divide the number by 2 and write the remainders as bits

Uploaded by

Ian Ndumia
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)
25 views9 pages

Number Systems

This document discusses different number systems used in computing, including binary, octal, and hexadecimal. It provides instructions on how to convert between decimal, binary, octal, and hexadecimal numbers. The key points are: - Binary numbers use only the digits 0 and 1 and have a base of 2. Octal uses digits 0-7 and has a base of 8. Hexadecimal uses digits 0-9 and A-F and has a base of 16. - To convert a binary number to decimal, you write it as a sum of terms with coefficients that are powers of 2. - To convert a decimal number to binary, you repeatedly divide the number by 2 and write the remainders as bits

Uploaded by

Ian Ndumia
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/ 9

Chapter 3

Binary, octal and


hexadecimal
The binary system of numbers has a radix of 2 and
3.1 Introduction uses only the digits 0 and 1.

All data in modern computers is stored as series of bits, a (a) Conversion of binary to decimal:
bit being a binary digit, and can have one of two values,
The decimal number 234.5 is equivalent to
the numbers 0 and 1. The most basic form of represent-
ing computer data is to represent a piece of data as a 2 × 102 + 3 × 101 + 4 × 100 + 5 × 10−1
string of 1’s and 0’s, one for each bit. This is called a
binary or base-2 number. i.e. is the sum of term comprising: (a digit) multiplied
Because binary notation requires so many bits to rep- by (the base raised to some power).
resent relatively small numbers, two further compact In the binary system of numbers, the base is 2, so
notations are often used, called octal and hexadeci- 1101.1 is equivalent to:
mal. Computer programmers who design sequences of
number codes instructing a computer what to do, would 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 + 1 × 2−1
have a very difficult task if they were forced to work
with nothing but long strings of 1s and 0s, the ‘native Thus the decimal number equivalent to the binary
language’ of any digital circuit. number 1101.1 is
Octal notation represents data as base-8 numbers
with each digit in an octal number representing three 1
8 + 4 + 0 + 1 + , that is 13.5
bits. Similarly, hexadecimal notation uses base-16 2
numbers, representing four bits with each digit. Octal
i.e. 1101.12 = 13.510 , the suffixes 2 and 10 denoting
numbers use only the digits 0–7, while hexadecimal
binary and decimal systems of number respectively.
numbers use all ten base-10 digits (0–9) and the letters
A–F (representing the numbers 10–15).
This chapter explains how to convert between the Problem 1. Convert 110112 to a decimal number
decimal, binary, octal and hexadecimal systems.

From above: 110112 = 1 × 24 + 1 × 23 + 0 × 22


3.2 Binary numbers + 1 × 21 + 1 × 20
= 16 + 8 + 0 + 2 + 1
The system of numbers in everyday use is the denary
or decimal system of numbers, using the digits 0 to 9. = 2710
It has ten different digits (0, 1, 2, 3, 4, 5, 6, 7, 8 and 9)
and is said to have a radix or base of 10.
DOI: 10.1016/B978-0-08-096562-8.00004-3
20 Engineering Mathematics
Section 1

Problem 2. Convert 0.10112 to a decimal fraction 5. (a) 11010.11 (b) 10111.011


(c) 110101.0111 (d) 11010101.10111
 
0.10112 = 1 × 2−1 + 0 × 2−2 + 1 × 2−3 (a) 26.7510 (b) 23.37510
+ 1 × 2−4 (c) 53.437510 (d) 213.7187510
1 1 1
= 1× +0× 2 +1× 3
2 2 2
(b) Conversion of decimal to binary:
1
+ 1× 4 An integer decimal number can be converted to a cor-
2
1 1 1 responding binary number by repeatedly dividing by 2
= + + and noting the remainder at each stage, as shown below
2 8 16
for 3910
= 0.5 + 0.125 + 0.0625
= 0.687510 2 39 Remainder
2 19 1
Problem 3. Convert 101.01012 to a decimal 2 9 1
number 2 4 1
2 2 0
2 1 0
101.01012 = 1 × 22 + 0 × 21 + 1 × 20
0 1
+ 0 × 2−1 + 1 × 2−2
(most 1 0 0 1 1 1 (least
+ 0 × 2−3 + 1 × 2−4 significant bit) significant bit)
= 4 + 0 + 1 + 0 + 0.25
The result is obtained by writing the top digit of the
+ 0 + 0.0625 remainder as the least significant bit, (a bit is a binary
= 5.312510 digit and the least significant bit is the one on the right).
The bottom bit of the remainder is the most significant
bit, i.e. the bit on the left.
Now try the following exercise
Thus 3910 = 1001112
Exercise 10 Further problems on
The fractional part of a decimal number can be converted
conversion of binary to
to a binary number by repeatedly multiplying by 2, as
decimal numbers
shown below for the fraction 0.625
In Problems 1 to 5, convert the binary numbers
given to decimal numbers. 0.625 3 2 5 1. 250

1. (a) 110 (b) 1011 (c) 1110 (d) 1001


0.250 3 2 5 0. 500
[(a) 610 (b) 1110 (c) 1410 (d) 910 ]

2. (a) 10101 (b) 11001 (c) 101101 (d) 110011 0.500 3 2 5 1. 000
[(a) 2110 (b) 2510 (c) 4510 (d) 5110 ]
(most significant bit) .1 0 1 (least significant bit)
3. (a) 101010 (b) 111000 (c) 1000001
(d) 10111000 For fractions, the most significant bit of the result is the
[(a) 4210 (b) 5610 (c) 6510 (d) 18410] top bit obtained from the integer part of multiplication
by 2. The least significant bit of the result is the bot-
4. (a) 0.1101 (b) 0.11001 (c) 0.00111 tom bit obtained from the integer part of multiplication
(d) 0.01011   by 2.
(a) 0.812510 (b) 0.7812510
(c) 0.2187510 (d) 0.3437510 Thus 0.62510 = 0.1012
Binary, octal and hexadecimal 21

The fractional part is repeatedly multiplied by 2

Section 1
Problem 4. Convert 4710 to a binary number
giving:
From above, repeatedly dividing by 2 and noting the
remainder gives: 0.3125 3 2 5 0.625
2 47 Remainder 0.625 3 2 5 1.25
0.25 3 2 5 0.5
2 23 1
0.5 325 1.0
2 11 1
.0 1 0 1
2 5 1
2 2 1
2 1 0 Thus 58.312510 = 111010.01012
0 1

1 0 1 1 1 1 Now try the following exercise

Thus 4710 = 1011112


Exercise 11 Further problems on
conversion of decimal
Problem 5. Convert 0.4062510 to a binary
to binary numbers
number
In Problems 1 to 5, convert the decimal numbers
From above, repeatedly multiplying by 2 gives: given to binary numbers.
0.40625 3 2 5 0. 8125 1. (a) 5 (b) 15 (c) 19 (d) 29
 
(a) 1012 (b) 11112
0.8125 325 1. 625
(c) 100112 (d) 111012

0.625 325 1. 25
2. (a) 31 (b) 42 (c) 57 (d) 63
0.25 325 0. 5  
(a) 111112 (b) 1010102
(c) 1110012 (d) 1111112
0.5 325 1. 0

.0 1 1 0 1 3. (a) 47 (b) 60 (c) 73 (d) 84


 
(a) 1011112 (b) 1111002
i.e. 04062510 = 0.011012
(c) 10010012 (d) 10101002
Problem 6. Convert 58.312510 to a binary
number 4. (a) 0.25 (b) 0.21875 (c) 0.28125
(d) 0.59375
The integer part is repeatedly divided by 2, giving:  
(a) 0.012 (b) 0.001112
2 58 Remainder (c) 0.010012 (d) 0.100112
2 29 0
2 14 1
2 7 0 5. (a) 47.40625 (b) 30.8125
2 3 1 (c) 53.90625 (d) 61.65625
2 1 1
 
(a) 101111.011012 (b) 11110.11012
0 1 (c) 110101.111012 (d) 111101.101012
1 1 1 0 1 0
22 Engineering Mathematics

(c) Binary addition: Now try the following exercise


Section 1

Binary addition of two/three bits is achieved according


to the following rules: Exercise 12 Further problems on binary
addition
sum carry sum carry
Perform the following binary additions:
0+0 = 0 0 0+0+0 = 0 0
0+1 = 1 0 0+0+1 = 1 0 1. 10 + 11 [101]
1+0 = 1 0 0+1+0 = 1 0 2. 101 + 110 [1011]
1+1 = 0 1 0+1+1 = 0 1
3. 1101 + 111 [10100]
1+0+0 = 1 0
1+0+1 = 0 1 4. 1111 + 11101 [101100]
1+1+0 = 0 1 5. 110111 + 10001 [1001000]
1+1+1 = 1 1
6. 10000101 + 10000101 [100001010]
These rules are demonstrated in the following worked 7. 11101100 + 111001011 [1010110111]
problems.
8. 110011010 + 11100011 [1001111101]
9. 10110 + 1011 + 11011 [111100]
Problem 7. Perform the binary addition:
10. 111 + 10101 + 11011 [110111]
1001 + 10110
11. 1101 + 1001 + 11101 [110011]
1001
12. 100011 + 11101 + 101110 [1101110]
+10110
11111

Problem 8. Perform the binary addition: 3.3 Octal numbers


11111 + 10101
For decimal integers containing several digits, repeat-
11111 edly dividing by 2 can be a lengthy process. In this case,
+10101 it is usually easier to convert a decimal number to a
sum 110100 binary number via the octal system of numbers. This
carry 11111 system has a radix of 8, using the digits 0, 1, 2, 3, 4,
5, 6 and 7. The denary number equivalent to the octal
Problem 9. Perform the binary addition: number 43178 is
1101001 + 1110101
4 × 8 3 + 3 × 8 2 + 1 × 81 + 7 × 8 0
1101001 i.e. 4 × 512 + 3 × 64 + 1 × 8 + 7 × 1 or 225510
+1110101
sum 11011110 An integer decimal number can be converted to a cor-
carry 1 1 1 responding octal number by repeatedly dividing by 8
and noting the remainder at each stage, as shown below
Problem 10. Perform the binary addition: for 49310
1011101 + 1100001 + 110101 8 493 Remainder
8 61 5
1011101
8 7 5
1100001
+110101 0 7
sum 11110011
carry 11111 1 7 5 5

Thus 49310 = 7558


Binary, octal and hexadecimal 23

The fractional part of a decimal number can be con- Dividing repeatedly by 8, and noting the remainder

Section 1
verted to an octal number by repeatedly multiplying by gives:
8, as shown below for the fraction 0.437510
8 3714 Remainder
0.4375 3 8 5 3. 5 8 464 2
8 58 0
0.5 385 4. 0 8 7 2
0 7
.3 4
7 2 0 2
For fractions, the most significant bit is the top integer
obtained by multiplication of the decimal fraction by 8,
From Table 3.1, 72028 = 111 010 000 0102
thus
i.e. 371410 = 111 010 000 0102
0.437510 = 0.348

The natural binary code for digits 0 to 7 is shown Problem 12. Convert 0.5937510 to a binary
in Table 3.1, and an octal number can be converted number, via octal
to a binary number by writing down the three bits
corresponding to the octal digit. Multiplying repeatedly by 8, and noting the integer
values, gives:
Thus 4378 = 100 011 1112
and 26.358 = 010 110.011 1012 0.59375 3 8 5 4.75
0.75 385 6.00
.4 6
Table 3.1
Octal digit Natural Thus 0.5937510 = 0.468
binary number
From Table 3.1, 0.468 = 0.100 1102
0 000
i.e. 0.5937510 = 0.100 112
1 001
Problem 13. Convert 5613.9062510 to a binary
2 010
number, via octal
3 011
The integer part is repeatedly divided by 8, noting the
4 100 remainder, giving:

5 101 8 5613 Remainder


8 701 5
6 110
8 87 5
7 111 8 10 7
8 1 2
0 1
The ‘0’ on the extreme left does not signify anything, 1 2 7 5 5
thus 26.358 = 10 110.011 1012
Conversion of decimal to binary via octal is demon- This octal number is converted to a binary number, (see
strated in the following worked problems. Table 3.1)

Problem 11. Convert 371410 to a binary number, 127558 = 001 010 111 101 1012
via octal
i.e. 561310 = 1 010 111 101 1012
24 Engineering Mathematics

The fractional part is repeatedly multiplied by 8, and


Section 1

noting the integer part, giving: 3. (a) 247.09375 (b) 514.4375


(c) 1716.78125
⎡ ⎤
0.90625 3 8 5 7.25 (a) 11110111.000112
0.25 385 2.00 ⎣ (b) 1000000010.01112 ⎦
(c) 11010110100.110012
.7 2
4. Convert the following binary numbers to dec-
This octal fraction is converted to a binary number, (see imal numbers via octal:
Table 3.1) (a) 111.011 1 (b) 101 001.01
(c) 1 110 011 011 010.001 1
0.728 = 0.111 0102  
(a) 7.437510 (b) 41.2510
(c) 7386.187510
i.e. 0.9062510 = 0.111 012

Thus, 5613.9062510 = 1 010 111 101 101.111 012


3.4 Hexadecimal numbers
Problem 14. Convert 11 110 011.100 012 to a
decimal number via octal The hexadecimal system is particularly important in
computer programming, since four bits (each consist-
ing of a one or zero) can be succinctly expressed using
Grouping the binary number in three’s from the binary
a single hexadecimal digit. Two hexadecimal digits
point gives: 011 110 011.100 0102
represent numbers from 0 to 255, a common range used,
Using Table 3.1 to convert this binary number to an
for example, to specify colours. Thus, in the HTML
octal number gives: 363.428 and
language of the web, colours are specified using three
pairs of hexadecimal digits RRGGBB, where RR is the
363.428 = 3 × 82 + 6 × 81 + 3 × 80 amount of red, GG the amount of green, and BB the
amount of blue.
+ 4 × 8−1 + 2 × 8−2
A hexadecimal numbering system has a radix of 16
= 192 + 48 + 3 + 0.5 + 0.03125 and uses the following 16 distinct digits:

= 243.5312510 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F
‘A’ corresponds to 10 in the denary system, B to 11, C
to 12, and so on.
Now try the following exercise

(a) Converting from hexadecimal to decimal:


Exercise 13 Further problems on
conversion between decimal For example
and binary numbers via octal
1A16 = 1 × 161 + A × 160
In Problems 1 to 3, convert the decimal numbers
= 1 × 161 + 10 × 1 = 16 + 10 = 26
given to binary numbers, via octal.
i.e. 1A16 = 2610
1. (a) 343 (b) 572 (c) 1265
  Similarly,
(a) 1010101112 (b) 10001111002
(c) 100111100012 2E16 = 2 × 161 + E × 160
= 2 × 161 + 14 × 160 = 32 + 14 = 4610
2. (a) 0.46875 (b) 0.6875 (c) 0.71875
  and 1BF16 = 1 × 162 + B × 161 + F × 160
(a) 0.011112 (b) 0.10112
(c) 0.101112 = 1 × 162 + 11 × 161 + 15 × 160
= 256 + 176 + 15 = 44710
Binary, octal and hexadecimal 25

Table 3.2 compares decimal, binary, octal and hexadec- Table 3.2

Section 1
imal numbers and shows, for example, that
Decimal Binary Octal Hexadecimal
2310 = 101112 = 278 = 1716
0 0000 0 0

Problem 15. Convert the following hexadecimal 1 0001 1 1


numbers into their decimal equivalents: (a) 7A16 2 0010 2 2
(b) 3F16
3 0011 3 3
(a) 7A16 = 7 × 161 + A × 160 = 7 ×16 +10 × 1 4 0100 4 4
= 112 +10 =122
Thus 7A16 = 12210 5 0101 5 5

(b) 3F16 = 3 × 161 + F × 160 = 3 × 16 +15 ×1 6 0110 6 6


= 48 +15 =63 7 0111 7 7
Thus, 3F16 = 6310
8 1000 10 8
Problem 16. Convert the following hexadecimal 9 1001 11 9
numbers into their decimal equivalents: (a) C916
(b) BD16 10 1010 12 A
11 1011 13 B
(a) C916 = C × 161 + 9 ×160 = 12 × 16 +9 × 1
12 1100 14 C
= 192 +9 =201
Thus C916 = 20110 13 1101 15 D

(b) BD16 = B × 161 + D × 160 = 11 ×16 +13 × 1 14 1110 16 E


= 176 +13 =189 15 1111 17 F
Thus, BD16 = 18910
16 10000 20 10
Problem 17. Convert 1A4E16 into a denary 17 10001 21 11
number
18 10010 22 12
1A4E16 19 10011 23 13
= 1 × 163 + A × 162 + 4 × 161 + E × 160 20 10100 24 14
= 1 × 16 + 10 × 16 + 4 × 16 + 14 × 16
3 2 1 0
21 10101 25 15
= 1 × 4096 + 10 × 256 + 4 × 16 + 14 × 1 22 10110 26 16
= 4096 + 2560 + 64 + 14 = 6734 23 10111 27 17
Thus, 1A4E16 = 673410 24 11000 30 18
25 11001 31 19
(b) Converting from decimal to hexadecimal:
26 11010 32 1A
This is achieved by repeatedly dividing by 16 and noting
27 11011 33 1B
the remainder at each stage, as shown below for 2610.
28 11100 34 1C
16 26 Remainder
16 1 10 ; A16 29 11101 35 1D
0 1 ; 116 30 11110 36 1E
most significant bit 1 A least significant bit 31 11111 37 1F

Hence 2610 = 1A16 32 100000 40 20


26 Engineering Mathematics

Similarly, for 44710 Now try the following exercise


Section 1

16 447 Remainder Exercise 14 Further problems on


16 27 15 ; F16 hexadecimal numbers
16 1 11 ; B16 In Problems 1 to 4, convert the given hexadecimal
0 1 ; 116 numbers into their decimal equivalents.
1 B F 1. E716 [23110] 2. 2C16 [4410]
3. 9816 [15210] 4. 2F116 [75310]
Thus 44710 = 1BF16
In Problems 5 to 8, convert the given decimal
numbers into their hexadecimal equivalents.
Problem 18. Convert the following decimal
numbers into their hexadecimal equivalents: 5. 5410 [3616] 6. 20010 [C816]
(a) 3710 (b) 10810
7. 9110 [5B16] 8. 23810 [EE16 ]
(a) 16 37 Remainder
16 2 5 5 516
(c) Converting from binary to hexadecimal:
0 2 5 216
The binary bits are arranged in groups of four, start-
2 5 ing from right to left, and a hexadecimal symbol is
most significant bit least significant bit assigned to each group. For example, the binary number
1110011110101001 is initially grouped in
Hence 3710 = 2516
fours as: 1110 0111 1010 1001
(b) 16 108 Remainder
and a hexadecimal symbol
16 6 12 5 C16
0 6 5 616 assigned to each group as E 7 A 9
6 C from Table 3.2

Hence 10810 = 6C16 Hence 11100111101010012 = E7A916

Problem 20. Convert the following binary


Problem 19. Convert the following decimal numbers into their hexadecimal equivalents:
numbers into their hexadecimal equivalents: (a) 110101102 (b) 11001112
(a) 16210 (b) 23910

(a) 16 162 Remainder (a) Grouping bits in fours from the


16 10 2 5 216
right gives: 1101 0110
and assigning hexadecimal symbols
0 10 5 A16
to each group gives: D 6
A 2 from Table 3.2

Hence 16210 = A216 Thus, 110101102 = D616

(b) 16 239 Remainder (b) Grouping bits in fours from the


16 14 15 5 F16 right gives: 0110 0111
0 14 5 E16 and assigning hexadecimal symbols
to each group gives: 6 7
E F from Table 3.2
Hence 23910 = EF16 Thus, 11001112 = 6716
Binary, octal and hexadecimal 27

Section 1
Problem 21. Convert the following binary Problem 23. Convert the following hexadecimal
numbers into their hexadecimal equivalents: numbers into their binary equivalents: (a) 7B16
(a) 110011112 (b) 1100111102 (b) 17D16

(a) Grouping bits in fours from the (a) Spacing out hexadecimal
right gives: 1100 1111 digits gives: 7 B
and assigning hexadecimal and converting each into
symbols to each group gives: C F binary gives: 0111 1011
from Table 3.2 from Table 3.2
Thus, 110011112 = CF16 Thus, 7B16 = 11110112
(b) Grouping bits in fours from (b) Spacing out hexadecimal
the right gives: 0001 1001 1110 digits gives: 1 7 D
and assigning hexadecimal and converting each into
symbols to each group gives: 1 9 E binary gives: 0001 0111 1101
from Table 3.2 from Table 3.2
Thus, 1100111102 = 19E16 Thus, 17D16 = 1011111012

(d) Converting from hexadecimal to binary: Now try the following exercise
The above procedure is reversed, thus, for example,
Exercise 15 Further problems on
6CF316 = 0110 1100 1111 0011 hexadecimal numbers
from Table 3.2
i.e. 6CF316 = 1101100111100112 In Problems 1 to 4, convert the given binary
numbers into their hexadecimal equivalents.
Problem 22. Convert the following hexadecimal 1. 110101112 [D716]
numbers into their binary equivalents: (a) 3F16 2. 111010102 [EA16 ]
(b) A616
3. 100010112 [8B16]
(a) Spacing out hexadecimal digits gives: 3 F 4. 101001012 [A516]
and converting each into In Problems 5 to 8, convert the given hexadecimal
binary gives: 0011 1111 numbers into their binary equivalents.
from Table 3.2 5. 3716 [1101112]
Thus, 3F16 = 1111112 6. ED16 [111011012]
(b) Spacing out hexadecimal digits 7. 9F16 [100111112]
gives: A 6 8. A2116 [1010001000012]
and converting each into binary
gives: 1010 0110
from Table 3.2
Thus, A616 = 101001102

You might also like