2. Binary Numbers and Binary Encoding 2.1 Number Systems Number systems come in a variety of forms where the numerical values of things are represented by a set of symbols of some form. Even colours can be used to represent numerical values, as for example in the Resistor Colour Code. We are interested in Positional Number Systems and in particular in the Decimal and Binary Number Systems. A Positional Number System has three essential properties: Radix: The term Radix is Latin meaning ‘root’. This is the base or foundation of the system and is essentially the number of individual numerical symbols or characters which are present in the system. There are ten symbols in the Decimal system and so it has a radix of 10, while there are only two symbols in the Binary system and so it has a radix of 2. Digits: The digits of a number system are the individual numerical symbols or characters which make up the system. The term ‘Bit’ is used to refer to a ‘Binary Digit’. Decimal Digits: 0 1 Binary Digits: 0 1 2 3 1 4 5 6 7 8 9 Positional Weighting: In a Positional Number System, several digits are combined to form a number which has a value. Each digit in the complete set may be utilised in each position. However, a different weight applies to each position and therefore the value of the same digit in a different position is different. In the Decimal and Binary number systems the weight is assigned positionally from right to left, in ascending order of exponent powers of the radix. That is, the significance of the digit increases from right to left as an increasing power of the radix. The digits also have an assigned order of increment with the increment between successive digits being of equal value. Decimal System Weighting: 100 106 ….. 105 104 103 102 101 MSD LSD Each weighted position is referred to as a Decade. The digit in the right hand most position is referred to as the Least Significant Digit (LSD), while that in the left hand most position is referred to as the Most Significant Digit (MSD). Binary System Weighting: 20 ….. 26 25 24 23 22 21 MSB LSB Each weighted position is referred to as a Binate, but this term is not common in practice and usually the term Bit is used, e.g. the first bit, the second bit, etc. The digit in the right hand most position is referred to as the Least Significant Bit (LSB), while that in the left hand most position is referred to as the Most Significant Bit (MSB). The term ‘Bit’ is generally used to refer to either the digits ‘0’ and ‘1’ as the characters of the Binary number system or to the weighted positions or binates of a Binary number. 2 2.2 Counting When counting in a positional number system, all of the digits are cycled through in their assigned order from the lowest to the highest in the least significant position. When the highest digit is reached in this position, it returns to the lowest digit and the digit in the next position to the left is incremented. This repeated cycling can continue indefinitely, with a gradual incrementing of digits in positions further to the left. Decimal Binary 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111 16 10000 17 10001 18 10010 19 10011 20 10100 21 10101 22 10110 3 2.3 Numerical Value The value of a number is determined by adding up the weighted values of all of the digits in the number. This is done by multiplying the digit at each location by the value of the exponent of the radix at the location in question. Take as an example the Decimal number 320795: The Value is obtained as: 105 3 104 2 103 0 102 7 Value = 3 x 105 + 2 x 104 + 0 x 103 + 7 x 102 + 101 9 100 5 9 x 101 + 5 x 100 3 x 105 = 3 x 100,000 = 300,000 2 x 104 = 2x 10,000 = 20,000 0 x 103 = 0x 1,000 = 0,000 7 x 102 = 7x 100 = 700 9 x 101 = 9x 10 = 90 5 x 100 = 5x 1 = 5 _______ 320,795 This is relatively straight forward as the value of a Decimal number has been obtained in Decimal form. 4 2.4 Binary Powers Before working on the values of Binary numbers it is useful to have a table of the Decimal values of powers of the radix 2. This will be convenient when dealing with Binary numbers having many digits. It will also allow familiarisation with some commonly used binary values, e.g. 1kbit, 1Mbit, etc. Binary Power 20 Decimal Value Binary Number 1 1 21 2 10 22 4 100 23 8 1000 24 16 10000 25 32 100000 26 64 1000000 27 128 10000000 28 256 100000000 29 512 1000000000 210 1,024 10000000000 1 kb 211 2,048 100000000000 2 kb 212 4,096 1000000000000 4 kb 213 8,192 10000000000000 8 kb 214 16,384 100000000000000 16 kb 215 32,768 1000000000000000 32 kb 216 65,536 10000000000000000 64 kb 217 131,072 100000000000000000 128 kb 218 262,144 1000000000000000000 256 kb 219 524,288 10000000000000000000 524 kb 220 1,048,576 100000000000000000000 1 Mb 230 1,073,741,824 1000000000000000000000000000000 1 Gb 5 2.5 Binary to Decimal Conversion Converting a Binary number into Decimal form is essentially the same thing as getting the decimal value of it. The same procedure can then be used as for finding the value of the Decimal number above except that the positional weightings applied will be those of a Radix 2 system. Consider the Binary number 101011 The Decimal value is obtained as: 25 1 24 0 23 1 Value = 1 x 25 + 0 x 24 + 1 x 23 + 22 0 21 1 0 x 22 + 1 x 21 20 1 + 1 x 20 1 x 25 = 1 x 32 = 32 0 x 24 = 0 x 16 = 0 1 x 23 = 1x8 = 8 0 x 22 = 0x4 = 0 1 x 21 = 1x2 = 2 1 x 20 = 1x1 = 1 ___ 43 Decimal With experience of this process the zero digit terms can be omitted for brevity. This means that only the powers of the radix which have a digit of ‘1’ entered in that position need to be summed. 6 Examples: 1. Binary 10111001 Value = 1 x 27 + 1 x 25 1 1 1 1 1 2. x x x x x + 27 25 24 23 20 1 x 24 = = = = = + 128 32 16 8 1 ___ 185 1 x 23 + 1 x 20 + 20 Decimal Binary 11101100101 Value = 210 + 29 + 28 + 210 29 28 26 25 22 20 26 = = = = = = = 7 + 25 1024 512 256 64 32 4 1 ____ 1893 + 22 Decimal 2.6 Decimal to Binary Conversion A Decimal number is converted to Binary form by continuously dividing it by the Binary radix 2 and saving the remainder. This process identifies the powers of the radix which are contained in the number and the remainder of each division operation determines the value of the bit in one weighted position at a time. The division process is continued until nothing remains to be divided into. The repeated division process yields the value of the digits of the number in Binary form but in reverse order and consequently the result of the process must be read backwards to extract the Binary number. Consider the decimal number 237: 2│237 2│118 1 2│59 0 2│29 1 2│14 1 2│7 0 2│3 1 2│1 1 0 1 11101101 Binary The resulting Binary number is read upwards through the remainders of the division process to obtain the Binary number reading from left to right. The result can form: Value = = = be checked by converting the number back to decimal 27 128 237 + 26 + 25 + + 64 + 32 + Decimal 8 23 8 + 22 + 4 + 20 + 1 Example: Consider the Decimal number 953: 2│953 2│476 1 2│238 0 2│119 0 2│59 1 2│29 1 2│14 1 2│7 0 2│3 1 2│1 1 0 1 1110111001 Binary Checking the result by converting back to Decimal: Value = 29 + 28 + 27 = 512 + 256 + 128 = 953 Decimal 9 + 25 + 32 + 24 + 16 + + 23 8 + + 20 1 2.7 Binary Encoding: Returning again to the analogue signals, it can be seen that if the analogue signal is transmitted over a medium where it will accumulate noise then the accuracy and resolution of the original measurement will be lost. If instead of transmitting the analogue signal we can transmit digital pulses then the effects of noise can be overcome. This is done by taking samples of the signal at particular points of interest, more usually at regular intervals in time, and encoding these values into digital pulse form for storage or transmission. Fig. 2.1 The Effect of Noise on Resolution Value at t = 250 ms is V = 54.3 mV with a resolution of 0.1 mV The encoding can be done in two popular ways. The first is to take the samples of the analogue signal at regular intervals and convert these into Binary form. This is the most common form of analogue-to-digital data conversion. In this case the value of 54.3 will be treated as 543 and converted to Binary form 543 Decimal = 1000011111 10 Binary Some form of scaling convention can be used to deal with the decimal point in the original sampled value. The binary number can then be transmitted as a series of digital pulses as indicated in Fig. 2.1: V 1 0 0 0 0 1 1 1 1 1 t Another common way to encode the sample is to encode each of the digits in the decimal number system into its equivalent binary form as shown below: Decimal Number 0 1 2 3 4 5 6 7 8 9 Binary Number 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 Each digit of a decimal value can then be coded as a 4-bit binary number. The decimal value can then be transmitted as a sequence of digital pulses. For example the decimal value 54.3 would be transmitted as 0101 0100 0111 Again, a convention can be used to identify the decimal point. The transmitted or stored pulses may become noisy but can be regenerated when received then decoded to recover the precise decimal value transmitted without error. 11