You are on page 1of 9

Number System

Computer Methods in Chemical Engineering


Table of Contents

Bit & Byte


K&M
Number System
Convert From Any Base To Decimal
Convert From Decimal to Any Base
Addition and Multiplication Tables
Arithmetic Operations
Comments

Bit & Byte


Computer uses the binary system. Any physical system that can exist in two distinct states (e.g.,
0-1, on-off, hi-lo, yes-no, up-down, north-south, etc.) has the potential of being used to represent
numbers or characters.
A binary digit is called a bit. There are two possible states in a bit, usually expressed as 0 and 1.
A series of eight bits strung together makes a byte, much as 12 makes a dozen. With 8 bits, or 8
binary digits, there exist 2^8=256 possible combinations. The following table shows some of
these combinations. (The number enclosed in parentheses represents the decimal equivalent.)
00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111

(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(

0)
1)
2)
3)
4)
5)
6)
7)
8)
9)
10)
11)
12)
13)
14)
15)

00010000
00010001
00010010
00010011
00010100
00010101
00010110
00010111
00011000
00011001
00011010
00011011
00011100
00011101
00011110
00011111

(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(

16)
17)
18)
19)
20)
21)
22)
23)
24)
25)
26)
27)
28)
29)
30)
31)

00100000
00100001
00100010
00100011
00100100
00100101
00100110
00100111
00101000
00101001
00101010
00101011
00101100
00101101
00101110
00101111

(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(

32)
33)
34)
35)
36)
37)
38)
39)
40)
41)
42)
43)
44)
45)
46)
47)

...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...

01110000
01110001
01110010
01110011
01110100
01110101
01110110
01110111
01111000
01111001
01111010
01111011
01111100
01111101
01111110
01111111

(112)
(113)
(114)
(115)
(116)
(117)
(118)
(119)
(120)
(121)
(122)
(123)
(124)
(125)
(126)
(127)

10100000 (160)
10100001 (161)

...
...

11110000 (240)
11110001 (241)

:
(continued)
:
10000000 (128)
10000001 (129)

10010000 (144)
10010001 (145)

10000010
10000011
10000100
10000101
10000110
10000111
10001000
10001001
10001010
10001011
10001100
10001101
10001110
10001111

(130)
(131)
(132)
(133)
(134)
(135)
(136)
(137)
(138)
(139)
(140)
(141)
(142)
(143)

10010010
10010011
10010100
10010101
10010110
10010111
10011000
10011001
10011010
10011011
10011100
10011101
10011110
10011111

(146)
(147)
(148)
(149)
(150)
(151)
(152)
(153)
(154)
(155)
(156)
(157)
(158)
(159)

10100010
10100011
10100100
10100101
10100110
10100111
10101000
10101001
10101010
10101011
10101100
10101101
10101110
10101111

(162)
(163)
(164)
(165)
(166)
(167)
(168)
(169)
(170)
(171)
(172)
(173)
(174)
(175)

...
...
...
...
...
...
...
...
...
...
...
...
...
...

11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
11111010
11111011
11111100
11111101
11111110
11111111

(242)
(243)
(244)
(245)
(246)
(247)
(248)
(249)
(250)
(251)
(252)
(253)
(254)
(255)

K&M
2^10=1024 is commonly referred to as a "K". It is approximately equal to one thousand. Thus, 1
Kbyte is 1024 bytes. Likewise, 1024K is referred to as a "Meg". It is approximately equal to a
million. 1 Mega byte is 1024*1024=1,048,576 bytes. If you remember that 1 byte equals one
alphabetical letter, you can develop a good feel for size.

Number System
You may regard each digit as a box that can hold a number. In the binary system, there can be
only two choices for this number -- either a "0" or a "1". In the octal system, there can be eight
possibilities:
"0", "1", "2", "3", "4", "5", "6", "7".
In the decimal system, there are ten different numbers that can enter the digit box:
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9".
In the hexadecimal system, we allow 16 numbers:
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", and "F".
As demonstrated by the following table, there is a direct correspondence between the binary
system and the octal system, with three binary digits corresponding to one octal digit. Likewise,
four binary digits translate directly into one hexadecimal digit. In computer usage, hexadecimal
notation is especially common because it easily replaces the binary notation, which is too long
and human mistakes in transcribing the binary numbers are too easily made.
Base Conversion Table
BIN
OCT
HEX
DEC
---------------------0000
00
0
0
0001
01
1
1
0010
02
2
2
0011
03
3
3
0100
04
4
4
0101
05
5
5
0110
06
6
6
0111
07
7
7
----------------------

1000
1001
1010
1011
1100
1101
1110
1111

10
11
12
13
14
15
16
17

8
9
A
B
C
D
E
F

8
9
10
11
12
13
14
15

Convert From Any Base To Decimal


Let's think more carefully what a decimal number means. For example, 1234 means that there
are four boxes (digits); and there are 4 one's in the right-most box (least significant digit), 3 ten's
in the next box, 2 hundred's in the next box, and finally 1 thousand's in the left-most box (most
significant digit). The total is 1234:
Original Number:

1
2
|
|
How Many Tokens:
1
2
Digit/Token Value: 1000
100
Value:
1000 + 200

or simply,

3
|
3
10
+ 30

4
|
4
1
+ 4

= 1234

1*1000 + 2*100 + 3*10 + 4*1 = 1234

Thus, each digit has a value: 10^0=1 for the least significant digit, increasing to 10^1=10,
10^2=100, 10^3=1000, and so forth.
Likewise, the least significant digit in a hexadecimal number has a value of 16^0=1 for the least
significant digit, increasing to 16^1=16 for the next digit, 16^2=256 for the next, 16^3=4096 for
the next, and so forth. Thus, 1234 means that there are four boxes (digits); and there are 4 one's
in the right-most box (least significant digit), 3 sixteen's in the next box, 2 256's in the next, and
1 4096's in the left-most box (most significant digit). The total is:
1*4096 + 2*256 + 3*16 + 4*1 = 4660

Example. Convert the hexadecimal number 4B3 to decimal notation. What about the decimal
equivalent of the hexadecimal number 4B3.3?
Solution:
Original Number:

4
B
|
|
How Many Tokens:
4
11
Digit/Token Value: 256
16
Value:
1024 +176

3
|
3
1
+ 3

3
|
3
0.0625
+ 0.1875

= 1203.1875

Example. Convert 234.14 expressed in an octal notation to decimal.


Solution:
Original Number:

|
|
How Many Tokens:
2
3
Digit/Token Value: 64
8
Value:
128 + 24

|
4
1
+ 4

|
1
0.125
+ 0.125 +

|
4
0.015625
0.0625

= 156.1875

Another way is to think of a cash register with different slots, each holding bills of a different
denomination.

Convert From Decimal to Any Base


Again, let's think about what you do to obtain each digit. As an example, let's start with a
decimal number 1234 and convert it to decimal notation. To extract the last digit, you move the
decimal point left by one digit, which means that you divide the given number by its base 10.
1234/10 = 123 + 4/10

The remainder of 4 is the last digit. To extract the next last digit, you again move the decimal
point left by one digit and see what drops out.
123/10 = 12 + 3/10

The remainder of 3 is the next last digit. You repeat this process until there is nothing left. Then
you stop. In summary, you do the following:
Quotient Remainder
----------------------------1234/10 =
123
4 --------+
123/10 =
12
3 ------+ |
12/10 =
1
2 ----+ | |
1/10 =
0
1 --+ | | |
| | | |
1 2 3 4

(Stop when the quotient is 0.)


(Base 10)

Now, let's try a nontrivial example. Let's express a decimal number 1341 in binary notation. Note
that the desired base is 2, so we repeatedly divide the given decimal number by 2.
Quotient Remainder
----------------------------1341/2 =
670
1 ----------------------+
670/2 =
335
0 --------------------+ |
335/2 =
167
1 ------------------+ | |
167/2 =
83
1 ----------------+ | | |
83/2 =
41
1 --------------+ | | | |
41/2 =
20
1 ------------+ | | | | |
20/2 =
10
0 ----------+ | | | | | |
10/2 =
5
0 --------+ | | | | | | |
5/2 =
2
1 ------+ | | | | | | | |
2/2 =
1
0 ----+ | | | | | | | | |
1/2 =
0
1 --+ | | | | | | | | | |
quotient is 0)
| | | | | | | | | | |
1 0 1 0 0 1 1 1 1 0 1

(Stop when the


(BIN; Base 2)

Let's express the same decimal number 1341 in octal notation.


Quotient Remainder
----------------------------1341/8 =
167
5 --------+
167/8 =
20
7 ------+ |
20/8 =
2
4 ----+ | |
2/8 =
0
2 --+ | | |
| | | |

(Stop when the quotient is 0)

2 4 7 5

(OCT; Base 8)

Let's express the same decimal number 1341 in hexadecimal notation.


Quotient Remainder
----------------------------1341/16 =
83
13 ------+
83/16 =
5
3 ----+ |
5/16 =
0
5 --+ | |
| | |
5 3 D

(Stop when the quotient is 0)


(HEX; Base 16)

Example. Convert the decimal number 3315 to hexadecimal notation. What about the
hexadecimal equivalent of the decimal number 3315.3?
Solution:
Quotient Remainder
----------------------------3315/16 =
207
3 ------+
207/16 =
12
15 ----+ |
12/16 =
0
12 --+ | |
| | |
C F 3
Product Integer Part
-------------------------------0.3*16
=
4.8
4
0.8*16
= 12.8
12
0.8*16
= 12.8
12
0.8*16
= 12.8
12
:
:
Thus, 3315.3 (DEC) --> CF3.4CCC...

(Stop when the quotient is 0)


(HEX; Base 16)
(HEX; Base 16)
0.4 C C C ...
| | | |
----+ | | | | |
------+ | | | |
--------+ | | |
----------+ | |
---------------------+
(HEX)

Note that from the Base Conversion Table, you can easily get the binary notation from the
hexadecimal number by grouping four binary digits per hexadecimal digit, or from or the octal
number by grouping three binary digits per octal digit, and vice versa.
HEX 5
3
D
BIN 0101 0011 1101
OCT 2
4
7
5
BIN 010 100 111 101

Finally, the fractional part is a decimal number can also be converted to any base by repeatedly
multiplying the given number by the target base. Example: Convert a decimal number 0.1234 to
binary notation
(BIN; Base 2)
Product Integer Part
0.0 0 0 1 1 1
-------------------------------| | | | | |
0.1234*2 = 0.2468
0
----+ | | | | |
0.2468*2 = 0.4936
0
------+ | | | |
0.4936*2 = 0.9872
0
--------+ | | |

1
|
|
|
|

1
|
|
|
|

1
|
|
|
|

0
|
|
|
|

0
|
|
|
|

1
|
|
|
|

...
|
|
|
|

0.9872*2
0.9744*2
0.9488*2
0.8976*2
0.7952*2
0.5904*2
0.1808*2
0.3616*2
0.7232*2

=
=
=
=
=
=
=
=
=
:
:

1.9744
1.9488
1.8976
1.7952
1.5904
1.1808
0.3616
0.7232
1.4464

1
1
1
1
1
1
0
0
1

----------+ | | | | | | | | |
------------+ | | | | | | | |
--------------+ | | | | | | |
----------------+ | | | | | |
------------------+ | | | | |
--------------------+ | | | |
----------------------+ | | |
------------------------+ | |
--------------------------+ |
----------------------------+

Additon and Multiplication Tables


You generate the addition tables in bases other then 10 by following the same rule you do in base
10. The resulting tables have the appearance of shifting the columns to the left by one in each
subsequent rows. Note how simple the addition and multiplication tables are for the binary
system; addition operation is simply the bit-wise XOR operation with carry, and multiplication is
simply the logical AND operation.
Decimal Addition Table:

| 0 1 2 3 4 5 6 7 8 9
---+----------------------------0 | 0 1 2 3 4 5 6 7 8 9
1 | 1 2 3 4 5 6 7 8 9 10
2 | 2 3 4 5 6 7 8 9 10 11
3 | 3 4 5 6 7 8 9 10 11 12
4 | 4 5 6 7 8 9 10 11 12 13
5 | 5 6 7 8 9 10 11 12 13 14
6 | 6 7 8 9 10 11 12 13 14 15
7 | 7 8 9 10 11 12 13 14 15 16
8 | 8 9 10 11 12 13 14 15 16 17
9 | 9 10 11 12 13 14 15 16 17 18
Binary Addition Table:
| 0 1
---+----0 | 0 1
1 | 1 10
Octal Addition Table:
| 0 1 2 3 4 5 6 7
---+----------------------0 | 0 1 2 3 4 5 6 7
1 | 1 2 3 4 5 6 7 10
2 | 2 3 4 5 6 7 10 11
3 | 3 4 5 6 7 10 11 12
4 | 4 5 6 7 10 11 12 13
5 | 5 6 7 10 11 12 13 14
6 | 6 7 10 11 12 13 14 15
7 | 7 10 11 12 13 14 15 16
Hexadecimal Addition Table:
| 0 1 2 3 4 5 6 7 8 9 A B C D E F
---+-----------------------------------------------

0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
5 6 7 8
6 7 8 9
7 8 9 A
8 9 A B
9 A B C
A B C D
B C D E
C D E F
D E F 10
E F 10 11
F 10 11 12

4
5
6
7
8
9
A
B
C
D
E
F
10
11
12
13

5
6
7
8
9
A
B
C
D
E
F
10
11
12
13
14

6
7
8
9
A
B
C
D
E
F
10
11
12
13
14
15

7
8
9
A
B
C
D
E
F
10
11
12
13
14
15
16

8
9
A
B
C
D
E
F
10
11
12
13
14
15
16
17

9
A
B
C
D
E
F
10
11
12
13
14
15
16
17
18

A
B
C
D
E
F
10
11
12
13
14
15
16
17
18
19

B
C
D
E
F
10
11
12
13
14
15
16
17
18
19
1A

C
D
E
F
10
11
12
13
14
15
16
17
18
19
1A
1B

D
E
F
10
11
12
13
14
15
16
17
18
19
1A
1B
1C

E
F
10
11
12
13
14
15
16
17
18
19
1A
1B
1C
1D

F
10
11
12
13
14
15
16
17
18
19
1A
1B
1C
1D
1E

You can also generate multiplication tables in bases other than 10 by following the same rule you
do in base 10.
Decimal Multiplication Table:
| 0 1 2 3 4 5 6 7 8 9
---+----------------------------0 | 0 0 0 0 0 0 0 0 0 0
1 | 0 1 2 3 4 5 6 7 8 9
2 | 0 2 4 6 8 10 12 14 16 18
3 | 0 3 6 9 12 15 18 21 24 27
4 | 0 4 8 12 16 20 24 28 32 36
5 | 0 5 10 15 20 25 30 35 40 45
6 | 0 6 12 18 24 30 36 42 48 54
7 | 0 7 14 21 28 35 42 49 56 63
8 | 0 8 16 24 32 40 48 56 64 72
9 | 0 9 18 27 36 45 54 63 72 81
Binary Multiplication Table:
| 0 1
---+----0 | 0 0
1 | 0 1
Octal Multiplication Table:
| 0 1 2 3 4 5 6 7
---+----------------------0 | 0 0 0 0 0 0 0 0
1 | 0 1 2 3 4 5 6 7
2 | 0 2 4 6 10 12 14 16
3 | 0 3 6 11 14 17 22 25
4 | 0 4 10 14 20 24 30 34
5 | 0 5 12 17 24 31 36 43
6 | 0 6 14 22 30 36 44 52
7 | 0 7 16 25 34 43 52 61
Hexadecimal Multiplication Table:
| 0 1 2 3 4 5 6 7 8 9 A B C D E F
---+----------------------------------------------0 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 | 0 1 2 3 4 5 6 7 8 9 A B C D E F

2
3
4
5
6
7
8
9
A
B
C
D
E
F

|
|
|
|
|
|
|
|
|
|
|
|
|
|

0
0
0
0
0
0
0
0
0
0
0
0
0
0

2
3
4
5
6
7
8
9
A
B
C
D
E
F

4
6
8
A
C
E
10
12
14
16
18
1A
1C
1E

6
9
C
F
12
15
18
1B
1E
21
24
27
2A
2D

8
C
10
14
18
1C
20
24
28
2C
30
34
38
3C

A
F
14
19
1E
23
28
2D
32
37
3C
41
46
4B

C
12
18
1E
24
2A
30
36
3C
42
48
4E
54
5A

E
15
1C
23
2A
31
38
3F
46
4D
54
5B
62
69

10
18
20
28
30
38
40
48
50
58
60
68
70
78

12
1B
24
2D
36
3F
48
51
5A
63
6C
75
7E
87

14
1E
28
32
3C
46
50
5A
64
6E
78
82
8C
96

16
21
2C
37
42
4D
58
63
6E
79
84
8F
9A
A5

18
24
30
3C
48
54
60
6C
78
84
90
9C
A8
B4

1A
27
34
41
4E
5B
68
75
82
8F
9C
A9
B6
C3

1C
2A
38
46
54
62
70
7E
8C
9A
A8
B6
C4
D2

1E
2D
3C
4B
5A
69
78
87
96
A5
B4
C3
D2
E1

Arithmetic Operations
You do arithematic with hexadecimal numbers or numbers in any base in exactly the same way
you do with decimal numbers, except that the addition and multiplcation tables you employ to
base your calculations are a bit different. Substraction is equivalent to adding a negative number,
and division is equivalent to multiplying by the inverse.
Example. Find the sum of two hexadecimal integers 123 and DEF.
Solution:
From the above hexadecimal addition table, we see that:
3+F=12, 2+E=10, and 1+D=E
123
+ DEF
----carry
11
E02
----sum
F12

Example. Find the product of two hexadecimal integers 123 and DEF.
Solution:
Step 1: We break down the second multiplier into single digits.
123*DEF = 123*(D00+E0+F)
= (123*D)*100 + (123*E)*10 + (123*F)
Step 2: We find the product in parentheses.
From the above hexadecimal multiplication table, we see that:
1*D=D, 2*D=1A, 3*D=27; thus,
123*D = (100+20+3)*D
= 1*D*100 + 2*D*10 + 3*D
= D*100
+ 1A*10 + 27
= D00
+ 1A0
+ 27
= EC7

Likewise,
123*E = (100+20+3)*E
= 1*E*100 + 2*E*10
= E*100
+ 1C*10
= E00
+ 1C0
= FEA
123*F = (100+20+3)*F
= 1*F*100 + 2*F*10
= F*100
+ 1E*10
= F00
+ 1E0
= 110D

+ 3*E
+ 2A
+ 2A
+ 3*F
+ 2D
+ 2D

Or, in elementary school style:


123
x
D
----27
1A
D
----EC7
Step 3: We sum up
123*DEF =
=
=
=

123
x
E
----2A
1C
E
----FEA

123
x
F
----2D
1E
F
----110D

the individual products.


(123*D)*100 + (123*E)*10 + (123*F)
EC7*100
+ FEA*10
+ 110D
EC700
+ FEA0
+ 110D
FD6AD

Or, in elementary school style:


123
x DEF
----110D
FEA
EC7
----FD6AD

You might also like