Thursday, February 28, 2013

Octal and Hexadecimal

hex codes

Octal and Hexadecimal

Octal numbers are numbers written in base 8. Hexadecimal numbers are numbers written in base 16.

Decimal

Binary

Octal

Hexadecimal

(base 10)

(base 2)

(base 8)

(base 16)

0

0000

0

0

1

0001

1

1

2

0010

2

2

3

0011

3

3

4

0100

4

4

5

0101

5

5

6

0110

6

6

7

0111

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

Fig 3 Conversion table for small numbers

Reasons for using octal and/or hexadecimal

Although they are stored in a computer in binary form, bit strings are often displayed by or entered into a computer in octal or hexadecimal form. This is because:

1- Binary strings are longer than their octal or hexadecimal equivalents. This means:

(a) Octal or hexadecimal strings do not take up much room when displayed.

(b) Binary strings take longer to type in.

2- Binary strings are difficult to recognize and remember.

3- As octal and hexadecimal are each based on a power of 2, they can be converted to and from binary easily.

CONVERSION BETWEEN HEXADECIMAL AND BINARY (INTEGERS) Every hexadecimal digit corresponds to four bits of the equivalent binary number.

Binary to hexadecimal

Method

1- Starting at the right split the binary number into groups of four bits.

2- Convert each group of bits to hexadecimal.

Worked question

A location contains the value 1001101011 in binary.

How would this be displayed in hexadecimal?

 

Comments

10

0110

1011

Starting at the right group into fours

For each group write hexadecimal equivalent

2

6

B

Answer 10011010112=26B16

Hexadecimal to binary

Method

1- For each hexadecimal digit write the four-digit binary equivalent.

2- Ignore any zeros at the left.

Worked question

The address of a location is 2B6A in hexadecimal. What is it in binary?

2

B

6

A

Comment

0010

1011

0110

1010

For each hexadecimal digit write the binary equivalent

The address is 0010 1011 0110 1010

Notes:

1- In the example addresses may occupy 16 bits so the two 1s at the left were not discarded.

2 -The methods for converting between octal and binary are similar with each octal digit corresponding to three binary digits.