Use the Browser Back Option to move back / Click here to Home Page

Computing Number Systems

(Binary, Decimal, Octal and Hexadecimal)

(1’s and 2’s complement)

Digits of the binary, octal, decimal and hexadecimal number systems

Binary Digit

Octal Digit

Decimal Digit

Hexadecimal Digit

0

0

0

0

1

1

1

1

 

2

2

2

 

3

3

3

 

4

4

4

 

5

5

5

 

6

6

6

 

7

7

7

 

 

8

8

 

 

9

9

 

 

 

A (decimal value of 10)

 

 

 

B (decimal value of 11)

 

 

 

C (decimal value of 12)

 

 

 

D (decimal value of 13)

 

 

 

E (decimal value of 14)

 

 

 

F (decimal value of 15)

 

Comparing the binary, octal, decimal and hexadecimal number systems.

Attribute

Binary

Octal

Decimal

Hexadecimal

Base

2

8

10

16

Lowest digit

0

0

0

0

Highest digit

1

7

9

F

 

Positional values in the decimal number system

 

Decimal digit

9

3

7

Positional name

Hundreds

Tens

Ones

Positional value

100

10

1

Positional value as a Power of the base (10)

102

101

100

For longer decimal numbers, the next positions to the left would be the thousands position (10 to the 3rd power), the ten-thousands position (10 to the 4th power), the hundred-thousands position (10 to the 5th power), the millions position (10 to the 6th power)_, the ten-millions position (10 to the 7th power) and so on.

Positional values in the binary number system

Binary digit

1

0

1

Position name

Fours

Twos

Ones

Positional value

4

2

1

Positional value as a Power of the bade (2)

22

21

20

For longer binary numbers, the next positions to the left would be the eights position (2 to the 3rd power), the sixteen’s position (2 to the 4th power), the thirty-twos position (2 to the 5th power), the sixty–fours position (2 to the 6th power) and so on.

In the octal number 425, we say that the 5 is written in the ones position, the 2 is written in the eights position, and the 4 is written in the sixty-fours position. Notice that each of these positions is a power of the base (base 8), and that these powers begin at 0 and increase by 1 as we move left in the number, given in below figure:

Positional values in the octal number system

Decimal Digit

4

2

5

Position name

Sixty-fours

Eights

Ones

Positional value

64

8

1

Positional value as a Power of the bade (8)

82

81

80

For longer octal numbers, the next positions to the left would be the five-hundred-and-twelve position (8 to the 3rd power), the four-thousand-and-ninety-sixes position (8 to the 4th power), the thirty-two-thousand-seven-hundred-and-sixty eights position (8 to the 5th power) and so on.

IN the Hexadecimal number #3DA, we say that the A is written in the ones position, the D is written in the sixteen’s position is a power of the base (base 16), and that these powers begin at 0 and increase by 1 as we move left in the number, given below:

Positional values in the hexadecimal number system

Decimal Digit

3

D

A

Position name

Two-hundred-and-fifty-sixes

Eights

Ones

Positional value

64

8

1

Positional value as a Power of the bade (16)

82

81

80

For longer hexadecimal numbers, the nest positions to the left would be the four-thousand-and-ninety-sixes position (16 to the 3rd power), the sixty-five-thousand-five-hundred-and-thirty-six position (16 to the 4th power) and so on.

Abbreviating binary numbers as octal and hexadecimal numbers

The main use for octal and hexadecimal numbers in computing is for abbreviating lengthy binary representations. The figure below highlights the fact that lengthy binary numbers can be expressed concisely in number systems with higher bases than the binary number system.

Decimal, Binary, Octal and Hexadecimal equivalents

Decimal Number

Binary Representation

Octal Representation

Hexadecimal Representation

0

0

0

0

1

1

1

1

2

10

2

2

3

11

3

3

4

100

4

4

5

101

5

5

6

110

6

6

7

111

7

7

8

1000

10

8

9

1001

11

9

10

1010

12

A

11

1011

13

B

12

1100

14

C

13

1101

15

D

14

1110

16

E

15

1111

17

F

16

10000

20

10

 

Binary Number        Octal Equivalent     Hexadecimal Equivalent

100011010001        4321                                        8D1

To see how the binary number converts easily to octal, simply break the 12-digit binary number into groups of three consecutive bits each, and write those groups over the corresponding digits of the octal number as follow:

100          011          010          001

4              3              2              1

Notice that the octal digit you have written under each group of the bits corresponds precisely to the octal equivalent of that 3-digit binary number as shown in the above figure.

The same kind of relationship may be observed in converting numbers from binary to hexadecimal. In particular, break the 12-digit binary number into groups of four consecutive bits each and write those groups over the corresponding digits of the hexadecimal number as follow:

1000        1101        0001

8              D              1

Converting Octal and Hexadecimal numbers to Binary numbers

In the section mentioned above , we saw how to convert binary numbers to their octal and hexadecimal equivalents by forming groups of binary digits and simply rewriting these groups as their equivalent octal digit values or hexadecimal digit values. This process may be used in reverse to produce the binary equivalent of a given octal or hexadecimal number.

For example, the octal number 653 is converted to binary simply by writing the 6 as its 3-digit binary equivalent 110, the 5 as its 3-digit binary equivalent 101 and the 3 as its 3-digit binary equivalent 011 to form the 9-digit binary number 110101011.

The hexadecimal number FAD5 is converted to binary simply by writing the F as its 4-digit binary equivalent 1111, the A as its 4-digit binary equivalent 1010, the D as its 4-digit binary equivalent 1101 and the 5 as its 4-digit binary equivalent 0101 to form the 16 digit 1111101011010101.

CONVERTING FROM BINARY, OCTAL OR HEXADECIMAL TO DECIMAL

Because we are accustomed to working in decimal, it is often convenient to convert a binary, octal or hexadecimal number to decimal to get sense of what the number is “really” worth. To convert a number to decimal from another base, multiply the decimal equivalent of each digit by its positional value, and sum these products. For example, the binary number 110101 is converted to decimal 53 in figure below:

Converting a binary number to decimal

Positional Values

32

16

8

4

2

1

Symbol Values

1

1

0

1

0

1

Products

1*32=32

1*16=16

0*8=0

1*4=4

0*2=0

1*1=1

Sum

=32+16+0+4+0+1 = 53

To convert octal number 7614 to decimal 3980, we use the same technique, the time using appropriate octal positional value as shown in figure below:

Converting a octal number to decimal

Positional Values

512

64

8

1

Symbol Values

7

6

1

4

Products

7*512=3584

6*64=384

1*8=8

4*1=4

Sum

=584+384+8+4=3980

To convert hexadecimal AD3B to decimal 44347, we use the same technique, this time using appropriate hexadecimal positional values as shown in fig below:

Converting a hexadecimal number to decimal

Positional Values

4096

256

16

1

Symbol Values

A

D

3

B

Products

A*4096=40960

D*256=3328

3*16=48

B*1=11

Sum

=40960+3328+48+11=44347

CONVERTING FROM DECIMAL TO BINARY,OCTAL OR HEXADECIMAL

The conversions of the previous section follow naturally from the positional notation conventions. Converting from decimal to binary, octal or hexadecimal also follows these conventions.

Suppose we wish to convert decimal 57 to binary. We begin by writing the positional values of the columns right to left until we reach a column whose positional values is greater than the decimal number. We do not need that column, so we discard it. Thus, we first write;

Positional Values:  64            32            16            8              4              2              1

then we discard the column with positional value 64 leaving:

Positional Values:  32            16            8              4              2              1

NEXT we work from the leftmost column to the right. We divide 32 into 57 and observe that there is one 32 in 57 with a remainder of 25, so we write 1 in the 32 column. We divide 16 into 25 and observe that there is one 16 in 25 with a remainder of 9 and write 1 in the 16 column. We divide 8 into 9 and observe that there is 8 in 9 with a remainder of 1. The next two columns each produce quotients of zero when their positional values are divided into 1 so we write 0s in the 4 and 2 column. Finally, 1 into 1 is 1 so we write 1 in the 1 column. This yields:

Positional Values:  32            16            8              4              2              1

Symbol Values:       1              1              1              0              0              1

and thus decimal 57 is equivalent to binary 111001

To convert decimal 103 to octal, we begin by writing the positional values of the columns until we reach a column whose positional value is greater than the decimal number:

We do not need that column, so we discard it. Thus, we first write:

Positional Values:  512          64            8              1

Then we discard the column with positional value 512, yielding:

Positional Values:  64            8              1

NEXT we work from the leftmost column to the right. We divide 64 into 103 and observe that there is one 64 in 103 with a remainder of 39, so we write 1 in the 64 column. We divide 8 into 39 and observe that there are four 8s In 39 with a reminder of 7 and write 4 in the 8 column. Finally, we divide 1 into 7 and observe that there are seven 1s in 7 with no remainder so we write 7 in the 1 column. This yields:

Positional Values:  64            8              1

Symbol Values:       1              4              7

and thus decimal 103 is equivalent to octal 147.

To convert decimal 375 to hexadecimal, we begin by writing the positional values of the columns until we reach a column whose positional value is greater than the decimal number. We do not need that column, so we discard it. Thus, we first write:

Positional Values:  4096        256          16            1

Then we discard the column with positional value 4096, yielding

Positional Values:  256          16            1

NEXT we work from the leftmost column to the right. We divide 256 into 375 and observe that there is one 256 in 375 and observe that there is one 256 in 375 with a remainder of 119, so we write 1 in the 256 column. We divide 16 into 119 and observer that there are seven 16s in 119 with a remainder of 7 and write 7 in the 16 columns. Finally, We divide 1 into 7 and observe that there are seven 1s in 7 with no remainder so we write 7 in the 1 column. This yield:

Positional Values:  256          16            1

Symbol Values:       1              7              7

and thus decimal 375 is equivalent to hexadecimal 177.

 

NEGATIVE BINARY NUMBERS: TWO’S COMPLEMENTS NOTATION

Here we will see how computers represent negative numbers using two’s complement notation.

Consider a machine with 32-bit integers. Suppose

VAR         VALUE     =              13;

The 32-bit representation of value is

00000000                00000000                000000000 00001101

To form the negative of value all the ones becomes ZERO and all ZEROs becomes 1’s as follows:

11111111                11111111                11111111                11110010

To form the two’s complement of value we simply add one to value’s one’s complement,

Thus,       Two’s complement of the above is

11111111                11111111                11111111                11110011

Now if this is in fact equal to –13, we should be able to add it to binary 13 and obtain a result of 0. Let us try this:

00000000                00000000                000000000 00001101

11111111                11111111                11111111                11110011

00000000                00000000                000000000 00000000

The carry bit coming out of the leftmost column is discarded and we indeed get zero as a result. If we add the one’s complement of a number to the number, the result would be all 1s. The key to getting a result of all zeros is that the twos complement is 1 more than the one’s complement. The addition of 1 causes each column to add to 0 with a carry of 1. The carry keeps moving leftward until it is discarded from the leftmost bit, and the resulting number is all zeros.

Computers actually perform a subtraction such as

x = a – value

by adding the two’s complement of value to a as follow:

x = a + (~value + 1);

Suppose A is 27 and value is 13 as before. If the two’s complement of value is actually the negative of value, then adding the two’s complement of value to a should produce the result 14. Let us try this:

a(i.e. 27)                    00000000              00000000                000000000 00011011

+(~value + 1)           11111111                11111111                11111111                11110011

----------------------------------------------------------------------------------

                                    00000000            00000000                000000000  00001110

which is indeed equal to 14.

 


Use the Browser Back Option to move back / Click here to Home Page

Copyright ©2005 Encycle Inc.