Contents:

    1. Counting in Binary, Octal, and Hexadecimal
    2. Base Conversion
    3. Gray Codes
    4. ASCII Codes

Counting in Binary, Octal, and Hexadecimal

The table below shows numbers in counting order for the decimal, binary, octal, and hexadecimal systems. The left column, shown in black, contains the decimal numbers from 0 to 28. The next three columns show the binary equivalent of each decimal number. The left binary column, shown in red, shows the five bit binary numbers containing only 0s and 1s. Since binary numbers are sums of powers of two, they tend to get rather long even for reasonably small numbers. It is often easier to work with the number if the bits are organized into groups of 3 or groups of 4. With groups of three, shown in blue, each group can be interpreted directly to an octal digit (base 8) without any arithmetic computation for the conversion. With groups of four, shown in green, each group can be interpreted directly to a hexadecimal digit (base 16) without any arithmetic computation for the conversion.

Decimal

Base 10

Binary

Base 2

Octal

Base 8

Hexadecimal

Base 16

no
grouping
group of
three bits
group of
four bits
00 00000 00 000 0 0000 00 00
01 00001 00 001 0 0001 01 01
02 00010 00 010 0 0010 02 02
03 00011 00 011 0 0011 03 03
04 00100 00 100 0 0100 04 04
05 00101 00 101 0 0101 05 05
06 00110 00 110 0 0110 06 06
07 00111 00 111 0 0111 07 07
08 01000 01 000 0 1000 10 08
09 01001 01 001 0 1001 11 09
10 01010 01 010 0 1010 12 0A
11 01011 01 011 0 1011 13 0B
12 01100 01 100 0 1100 14 0C
13 01101 01 101 0 1101 15 0D
14 01110 01 110 0 1110 16 0E
15 01111 01 111 0 1111 17 0F
16 10000 10 000 1 0000 20 10
17 10001 10 001 1 0001 21 11
18 10010 10 010 1 0010 22 12
19 10011 10 011 1 0011 23 13
20 10100 10 100 1 0100 24 14
21 10101 10 101 1 0101 25 15
22 10110 10 110 1 0110 26 16
23 10111 10 111 1 0111 27 17
24 11000 11 000 1 1000 30 18
25 11001 11 001 1 1001 31 19
26 11010 11 010 1 1010 32 1A
27 11011 11 011 1 1011 33 1B
28 11100 11 100 1 1100 34 1C


Base Conversion

Conversion from binary to decimal using decimal arithmetic is accomplished by simply summing the powers of 2 corresponding to 1s in the binary number. For example the binary number 10111 =b4 b3 b2 b1 b0 is converted to decimal by adding b4x16 + b3x8 + b2x4 + b1x2 +b0x1 = 1x16 + 0x8 + 1x4 + 1x2 +1x1 = 16+4+2+1=(23)decimal.

Conversion from decimal to binary using decimal arithmetic is accomplished by repeated division of the decimal number by two. After each division, the remainder is the next bit of the binary number (starting from the least significant). For example, the decimal number 26 is converted to binary as follows:

26/2

=

13

R=0

=b0

13/2

=

6

R=1

=b1

6/2

=

3

R=0

=b2

3/2

=

1

R=1

=b3

1/2

=

0

R=1

=b4

0/2

=

0

So (26)decimal = (11010)binary.

Conversion between binary and bases which are powers of 2( such as octal or hexadecimal) requires no arithmetic computation. For example, the decimal number 19 = 1x10 + 9x1 is written as a binary number with 10011=1x16 + 0x8 + 0x4 + 1x2 +1x1. If this number is interpreted in groups of three bits ( start the grouping from the right or the least significant bit) then each group of three can be interpreted as an octal digit multiplying a power of 8.

(10011)binary = 1x16 + 0x8 + 0x4 + 1x2 +1x1 = (1x16 +0x8) + (0x4 + 1x2 + 1x1) = 2x8 + 3x1 = (23)octal

Similarly, when groups of 4 bits are used, each group can be interpreted as a hexadecimal digit multiplying a power of 16.

(10011)binary = 1x16 + 0x8 + 0x4 + 1x2 +1x1 = (1x16) + (0x8 + 0x4 + 1x2 + 1x1) = 1x16 + 3x1 = (13)hexadecimal


Gray Codes

A gray code is a sequence of binary numbers in which only one bit changes with each step through the sequence. A sequence of binary numbers with one bit must be only 0 or 1. A sequence of two bit numbers can have four values. If a leading zero is added to the one bit numbers, we have 00 and 01 for the first two elements of the sequence. If the leading bit is cahnged to 1, then the other bit must not change, so the original sequence goes in reverse order when the leading bit is 1. Thus, the four element sequence is 00, 01, 11, 10. This can be repeated to make an 8 element sequence of three bit numbers by adding a a leading 0 to the 2 bit numbers to make the first four and adding a leading 1 to the 2 bit numbers in reverse order to make the second four.

Gray Codes for

1 to 4 bit words

1 bit 2 bit 3 bit 4 bit
0 00 000 0000
1 01 001 0001
11 011 0011
10 010 0010
110 0110
111 0111
101 0101
100 0100
1100
1101
1111
1110
1010
1011
1001
1000


ASCII CODES - 7 bits

ASCII stands for the American National Standard Code for Information Interchange. It was developed for computer communication systems and was adopted in 1963. It replaced a 5 bit code with shift states called theBaudot code which was developed for multiplexed telegraph systems and was used in Telex machines.

7-bit ASCII Codes

Control Codes

00-1F

Numbers and

Special Characters

40-3F

Upper Case

Characters

40-5F

LowerCase

Characters

60-7F

ASCIII octal hex ASCIII octal hex ASCII octal hex ASCIII octal hex
Null 000 00 space 040 20 @ 100 40 140 60
001 01 ! 041 21 A 101 41 a 141 61
002 02 " 042 22 B 102 42 b 142 62
003 03 # 043 23 C 103 42 c 143 63
EOT 004 04 $ 044 24 D 104 44 d 144 64
005 05 % 045 25 E 105 45 e 145 65
008 06 & 046 26 F 106 46 f 146 66
bell 007 07 ' 047 27 G 107 47 g 147 67
010 08 ( 050 28 H 110 48 h 150 68
011 09 ) 051 29 I 111 49 i 151 69
lf 012 0A * 052 2A J 112 4A j 152 6A
013 0B + 053 2B K 113 4B k 153 6B
ff 014 0C ' 054 2C L 114 4C l 154 6C
cr 015 0D - 055 2D M 115 4D m 155 6D
016 0E . 056 2E 4E
017 0F / 057 2F 4F
020 10 0 060 30 50
DC1 021 11 1 061 31 51
DC2 022 12 2 062 32 52
DC3 023 13 3 063 33 53
DC4 024 14 4 064 34 54
025 15 5 065 35 55
026 16 6 066 36 56
027 17 7 067 37 57
030 18 8 070 38 58
031 19 9 071 39 59
032 1A : Z 132 5A z 172 7A
ESC 033 1B ;
034 1C <
035 1D =
036 1E >
037 1F ?

Supplemental Material for ELEN 021, Logic Design

(c) Copyright 1998 Sally L, Wood