<< Chapter < Page | Chapter >> Page > |
Because of the nature of the digital systems, it is necessary to be able to represent numbers as being composed of only 1’s and 0’s. Ordinarily we represent numbers using the characters 0-9, and this notation is called base 10 or decimal notation. Using only the characters 1 and 0 is called binary notation or base 2 (because there are only 2 characters to represent the number instead of 10).Converting integers between these two systems is easy. In base 10 each decimal place represents the number of a certain power of 10.Thus the one’s place(10^0), 10’s place(10^1), 100’s place (10^2) etc. In base 2 each place represents a corresponding power of 2.
To convert a base 10 number into its base 2 form, begin at the 2’s place of the largest power of two smaller than the base 10 number you are converting. This will be the highest 1 digit of the base two number.Now see if the next smaller power of 2 is larger than the reminder of your base 10 number. If it is the next place in the base two number is a 0 if its smaller,subtract the power of two from the base 10 number and put a 1 in the next place. Repeat this until you have reached the 2^0 place.To convert back, go through each power of two place in the binary number and multiply it by the corresponding power of two. Sum these products to get the decimal version of the binary number.
This method works backwards also, starting from and expanding each digit by its appropriate exponent.
Hexadecimal is another numerical convention that is really base 16 . It uses the characters 0-9 for its first 10 numbers and the letters A-F to represent 10 through 15.Conversion between it and base 10 numbers proceeds the same as base 2 substituting powers of 16 for powers of 2. However, the important use of hexadecimal numbers is as an abbreviation for binary;because binary representation of large numbers becomes quite long. When programming, hexadecimal numbers should be prefaced with 0x to indicate that they are hexadecimal numbersrather than variable names etc. Thus 14 is a decimal number in C, and 0x14 is a hexadecimal number (actually equal to 20 in decimal). Below is a the list of expansions for hexadecimal to binary to decimal.
Notification Switch
Would you like to follow the 'Microcontroller and embedded systems laboratory' conversation and receive update notifications?