Review these topic from S1:
Signed integers
Section titled “Signed integers”To denote signed integers, there are 3 approaches.
- Sign-and-magnitude
- One’s complement
- Two’s complement
Sign-and-magnitude
Section titled “Sign-and-magnitude”MSB denotes the sign. Remaining bits denote the magnitude.
2 problems with this representation:
- Two zeros ( and )
- Arithmetic is cumbersome
Special formats
Section titled “Special formats”Binary Coded Decimal
Section titled “Binary Coded Decimal”Aka. BCD. Each digit is represented by a fixed set of bits. Usually in length 4 or 8. Only 10 of the available representations are used.
Gray codes
Section titled “Gray codes”Aka. reflected binary. An ordering of the binary numeral system such that two successive values differ only by 1 bit. Named after Frank Gray. Useful in minimizing errors in digital systems, especially in state transitions.
If two adjacent states have more than 1 bit changed (eg: 3 and 4), then the value transition might take some noticable time and could lead to issues.
A gray code is said to be cyclic, if the first and last numbers also differ by only a bit.
Generating gray code for n bits
Section titled “Generating gray code for n bits”To generate the Gray code for n bits:
- Start with the Gray code for 1 bit:
0and1. - For each additional bit:
- Reflect the current sequence (write it in reverse order).
- Prefix the original sequence with
0. - Prefix the reflected sequence with
1.
Example
Section titled “Example”For 2-bit Gray codes:
00011110
For 3-bit Gray codes:
000001011010110111101100