NUMBER SYSTEMS AND CODES



NUMBER SYSTEMS AND CODES

Topics to be covered:

• Number systems

– Number notations

– Arithmetic

– Base conversions

– Signed number representation

• Codes

– Decimal codes

– Error detection code

– Gray code

– ASCII code

1. Number Systems

The decimal (real), binary, octal hexadecimal number systems are used to represent information in digital systems. Any number system consists of a set of digits and a set of operators (+, (, (, (). The radix or base of the number system denotes the number of digits used in the system.

|Decimal (base 10) |0 1 2 3 4 5 6 7 8 9 |

|Binary (base 2) |0 1 |

|Octal (base 8) |0 1 2 3 4 5 6 7 |

|Hexadecimal (base 16) |0 1 2 3 4 5 6 7 8 9 A B C D E F |

|Decimal |Binary |Octal |Hexadecimal |

|00 |0000 |00 |0 |

|01 |0001 |01 |1 |

|02 |0010 |02 |2 |

|03 |0011 |03 |3 |

|04 |0100 |04 |4 |

|05 |0101 |05 |5 |

|06 |0110 |06 |6 |

|07 |0111 |07 |7 |

|08 |1000 |10 |8 |

|09 |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 |

1. Number notations

A number can be represented in either positional notation or polynomial notation.

Positional notation

It is convenient to represent a number using positional notation. A positional notation is written as a sequence of digits with a radix point separating the integer and fractional part.

[pic]

where r is the radix, n is the number of digits of the integer part, and m is the number digits of the fractional part.

Polynomial notation

A number can be explicitly represented in polynomial notation.

[pic]

where rp is a weighted position and p is the position of a digit.

In decimal number system

[pic]

In binary number system

[pic]

In octal number system

[pic]

In hexadecimal number system

[pic]

2. Arithmetic

Addition

In binary number system,

|(101101)2 +(11101)2 : |1111 1 |

|+ | 101101 |

| | 11101 |

| |1001010 |

In octal system,

|(6254)8 +(5173)8 : |1 1 |

|+ | 6254 |

| | 5173 |

| |13447 |

In hexadecimal system,

|(9F1B)16 +(4A36)16 : | 1 1 |

|+ | 9F1B |

| | 4A36 |

| | D951 |

Subtraction

In binary number system,

|(101101)2 -(11011)2 : | 10 10 |

|- | 101101 |

| | 11011 |

| | 10010 |

In octal system,

|(6254)8 -(5173)8 : | 8 |

|- | 6254 |

| | 5173 |

| | 1061 |

In hexadecimal system,

|(9F1B)16 -(4A36)16 : | 16 |

|- | 9F1B |

| | 4A36 |

| | 54E5 |

Multiplication

In binary number system,

|(1101)2 ( (1001)2 : | |

|( | 1101 |

| | 1001 |

| | 1101 |

| | 0000 |

| | 0000 |

| |1101 |

| |1110101 |

Division

In binary number system,

|(1110111)2 ((1001)2 : | 1101 |

|1001 |1110111 |

| |1001 |

| | 1011 |

| | 1001 |

| | 1011 |

| | 1001 |

| | 10 |

3. Base conversions

Convert (100111010)2 to base 8

[pic]

or

[pic]

Convert (100111010)2 to base 10

[pic]

Convert (100111010)2 to base 16

[pic]

or

[pic]

Convert (372)8 to base 2

[pic]

Convert (372)8 to base 10

[pic]

Convert (372)8 to base 16

[pic]

Convert (9F2)16 to base 2

[pic]

Convert (9F2)16 to base 8

[pic]

Convert (9F2)16 to base 10

[pic]

Binomial expansion (series substitution)

To convert a number in base r to base p.

1) Represent the number in base p in binomial series.

2) Change the radix or base of each term to base p.

3) Simplify.

Convert base 10 to base r

Convert (174)10 to base 8

|8 |1 |7 |4 | |6 |LSB |

| |8 |2 |1 | |5 | |

| | |8 |2 | |2 |MSB |

| | | |0 | | | |

Therefore (174)10 = (256)8

Convert (0.275)10 to base 8

|8 |( |0.275 |( |2.200 |MSD |

|8 |( |0.200 |( |1.600 | |

|8 |( |0.600 |( |4.800 | |

|8 |( |0.800 |( |6.400 | |

|8 |( |0.400 |( |3.200 |LSD |

Therefore (0.275)10 = (0.21463()8

Convert (0.68475)10 to base 2

|2 |( |0.68475 |( |1. 3695 |MSD |

|2 |( |0.3695 |( |0.7390 | |

|2 |( |0.7390 |( |1.4780 | |

|2 |( |0.4780 |( |0.9560 | |

|2 |( |0.9560 |( |1.9120 |LSD |

Therefore (0.68475)10 = (0.10101()2

4. Signed Number Representation

There are 3 systems to represent signed numbers:

• Signed-magnitude

• 1's complement

• 2's complement

In binary number system

Signed-magnitude system In signed-magnitude systems, the most significant bit represents the number's sign, while the remaining bits represent its absolute value as an unsigned binary magnitude.

• If the sign bit is a 0, the number is positive.

• If the sign bit is a 1, the number is negative.

1's Complement system A 1's complement system represents the positive numbers the same way as in the signed-magnitude system. The only difference is negative number representations.

Let be N any positive integer number and [pic] be a negative 1's complement integer of N. If the number legnth is n bits, then [pic] For example in a 4-bit system, 0101 represents +5 and

[pic]

1010 represents (5

2's Complement System A 2's complement system is similar to 1's complement system, except that there is only one representation for zero.

Let be N any positive integer number and [pic] be a negative 2's complement integer of N. If the length of the number is n bits, then [pic] For example in a 4-bit system, 0101 represents +5 and

[pic]

1011 represents (5

Adding and subtracting signed numbers

Signed-magnitude system

|(a) |5 | | 0101 |

| |+2 | |+0010 |

| |7 | | 0111 |

|(b) |-5 | | 1101 |

| |-2 | |+1010 |

| |-7 | | 1111 |

|(c) |5 | | 0101 |

| |-2 | |+1010 |

| |3 | | 0011 |

|(d) |-5 | | 1101 |

| |+2 | |+0010 |

| |-3 | | 1011 |

1's complement system

|(a) |5 | | 0101 |

| |+2 | |+0010 |

| |7 | | 0111 |

|(b) |-5 | | 1010 |

| |-2 | |+1101 |

| |-7 | | 1 0111 |

| | | |1 |

| | | | 1000 |

|(c) |5 | | 0101 |

| |-2 | |+1101 |

| |3 | | 1 0010 |

| | | |1 |

| | | | 0011 |

|(d) |-5 | | 1010 |

| |+2 | |+0010 |

| |-3 | | 1100 |

2's complement system

|(a) |5 | | 0101 |

| |+2 | |+0010 |

| |7 | | 0111 |

|(b) |-5 | | 1011 |

| |-2 | |+1110 |

| |-7 | | 1 1001 |

|(c) |5 | | 0101 |

| |-2 | |+1110 |

| |3 | | 1 0011 |

|(d) |-5 | | 1011 |

| |+2 | |+0010 |

| |-3 | | 1101 |

Overflow conditions

Carry-in ( carry-out

| | | 0111 |

|5 | |0101 |

|+3 | |+0011 |

| -8 | | 1000 |

| | | 1000 |

|-5 | |1011 |

|-4 | |+1100 |

| 7 | | 1 0111 |

Carry-in = carry-out

| | | 0000 |

|5 | |0101 |

|+2 | |+0010 |

| 7 | | 0111 |

| | | 1110 |

|-6 | |1010 |

|-2 | |+1110 |

| -8 | | 1 1000 |

2. Codes

1. Decimal codes

|Decimal Digit |BCD |Excess-3 |2421 |

| |8421 | | |

|0 |0000 |0011 |0000 |

|1 |0001 |0100 |0001 |

|2 |0010 |0101 |0010 |

|3 |0011 |0110 |0011 |

|4 |0100 |0111 |0100 |

|5 |0101 |1000 |1011 |

|6 |0110 |1001 |1100 |

|7 |0111 |1010 |1101 |

|8 |1000 |1011 |1110 |

|9 |1001 |1100 |1111 |

2. Error detection code

Parity bit

|Odd Parity | |Even Parity |

|P |Message | |P |Message |

|1 |0000 | |0 |0000 |

|0 |0001 | |1 |0001 |

|0 |0010 | |1 |0010 |

|1 |0011 | |0 |0011 |

|0 |0100 | |1 |0100 |

|1 |0101 | |0 |0101 |

|1 |0110 | |0 |0110 |

|0 |0111 | |1 |0111 |

|0 |1000 | |1 |1000 |

|1 |1001 | |0 |1001 |

|1 |1010 | |0 |1010 |

|0 |1011 | |1 |1011 |

|1 |1100 | |0 |1100 |

|0 |1101 | |1 |1101 |

|0 |1110 | |1 |1110 |

|1 |1111 | |0 |1111 |

3. Gray code

|Decimal Equivalent |Binary Code |Gray Code |

|0 |0000 |0000 |

|1 |0001 |0001 |

|2 |0010 |0011 |

|3 |0011 |0010 |

|4 |0100 |0110 |

|5 |0101 |0111 |

|6 |0110 |0101 |

|7 |0111 |0100 |

|8 |1000 |1100 |

|9 |1001 |1101 |

|10 |1010 |1111 |

|11 |1011 |1110 |

|12 |1100 |1010 |

|13 |1101 |1011 |

|14 |1110 |1001 |

|15 |1111 |1000 |

4. ASCII code

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

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download