<< Chapter < Page Chapter >> Page >
Explains binary and hexadecimal numbers and how to convert them.

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.

    Steps in converting to base 2

  • 721 512 209 so the first bit is 1 2 9
  • 209 256 so the second bit is 0 2 8
  • 209 128 81 so the third bit is 0 2 7
  • 81 64 17 so the fourth bit is 1 2 6
  • 17 32 so the fifth bit is 0 2 5
  • 17 16 1 so the sixth bit is 1 2 4
  • 1 8 so the seventh bit is 0 2 3
  • 1 4 so the eigth bit is 0 2 2
  • 1 2 so the ninth bit is 0 2 1
  • 1 1 0 so the tenth bit is 1 2 0
  • thus the conversion: 721 1011010001

This method works backwards also, starting from 1011010001 and expanding each digit by its appropriate exponent.

Got questions? Get instant answers now!

What is 293 in binary? What is 1110001 in decimal?

293 100100101 and 1110001 113

Got questions? Get instant answers now!

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.

    Binary to hexadecimal equivalence

  • 0000 0 0
  • 0001 1 1
  • 0010 2 2
  • 0011 3 3
  • 0100 4 4
  • 0101 5 5
  • 0110 6 6
  • 0111 7 7
  • 1000 8 8
  • 1001 9 9
  • 1010 A 10
  • 1011 B 11
  • 1100 C 12
  • 1101 D 13
  • 1110 E 14
  • 1111 F 15

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Microcontroller and embedded systems laboratory. OpenStax CNX. Feb 11, 2006 Download for free at http://cnx.org/content/col10215/1.29
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Microcontroller and embedded systems laboratory' conversation and receive update notifications?

Ask