Binary is a way of representing integers using only two digits - 0 and 1. Knowledge of the binary number system is sometimes useful in programming.
The number system we normally use is the decimal system using digits 0 to 9. Consider a number, say 1079. What does it mean? It means:
1 * 103 + 0 * 102 + 7 * 101 + 9 * 100
In other words, we first number the digits of the number from right to left, zero to three. Then we multiply the value of each digit with the corresponding power of ten, and add the results for each digit.
The basic idea behind the binary system is the same, except that powers of two are used instead of ten. For example,
10110101 = 1 * 27 + 0 * 26 + 1 * 25 + 1 * 24 + 0 * 23 + 1 * 22 + 0 * 21 + 1 * 20
= 128 + 32 + 16 + 4 + 1
= 181
The above procedure is used to convert binary numbers to decimal. On the other hand, you may need to convert decimal to binary. To do that, one divides the number by two, to get the quitient and remainder. The remainder is either zero, or one, and forms the rightmost binary digit (bit). Then divide the quotient to get the next bit, and quotient. Repeat this process till you end up with zero as quotient. For example, to convert 181 from decimal to binary
181 / 2 --> Q = 90 R = 1
90 / 2 --> Q = 45 R = 0
45 / 2 --> Q = 22 R = 1
22 / 2 --> Q = 11 R = 0
11 / 2 --> Q = 5 R = 1
5 / 2 --> Q = 2 R = 1
2 / 2 --> Q = 1 R = 0
1 / 2 --> Q = 0 R = 1
Write the remainders from right to left, to get 10110101. This, is of course the very binaty number we'd converted to decimal and found equal to 181.
The hexadecimal system uses sixteen digits. From 0 to 9 and A to F. Digits A to F have values from 10 to 15. The binary system is used because it is the only system that the computer itself recognises. However, values represented in binary tend to be very long, and difficult to remember. It is much easier to convert between hexadecimal (usually called hex) to binary, than binary and decimal. Hex numbers are much shorter than the corresponding value in binary.
You can convert from hex to decimal by multiplying digits with powers of sixteen. Similarly you can use the method used to convert from decimal to binary, to convert from decimal to hex, by dividing by sixteen instead of two, to get remainders from 0 to 15.
However, the most common use of hex is easy conversion to and from binary. To convert from hex to binary, just convert each digit to binary, and write the corresponding binary values in the order of the hex digits! However, remember that each digit should be four bits long. Add zeroes to the left of necesary. For example, 5 should be weitten as 0101, not 101.
( 1) (15) ( 8)
1F8 = 0001 1111 1000
So, 1F8 (hex) is 000111111000 (binary)
To convert from binary to hex, divide the binary number in groups of four bits from right to left. Each group will have a value between zero and fifteen. Simply write the hex digit corresponding to the number. For example to convert 11011110110 to hex, write it as
0110 1111 0110
( 6) (15) ( 6)
6 F 6
So the corresponding hex number is 6F6.
Like Hexadecimal which uses sixteen digits, there is the Octal system which uses eight digits, 0-7. After studying the binary and hexadecimal systems, you should be able to figure out this one for yourself. You can convert to and from decimal using powers of eight. You can convert to and from binary using groups of three bits. The Octal system is rarely used in practice.Actually, different number systems are more a matter of mathematics than computers. Computers just became a reason to use binary and hex. In fact there is nothing special about the bases two, eight, ten and sixteen. You might as well have a number system using any other number of digits. Its just that there has never been a real reason to uses any other system.
This convertor only supports bases from 2 to 36. Its mathematically not possible to have numbers with base less than 2. Numbers with bases greater than 36 are possible, but the converter does not support them because there are no standard characters that can be used to represent such numbers. The first 36 characters will be 0-9 and A-Z. But what should you use for the 37th character?
One binary digit is called a bit. There are special names for larger groups of bits:
Number of Bits | Name |
---|---|
4 | Nibble |
8 | Byte |
16 | Word |
32 | Double Word |
64 | Quad Word |
80 | Tenbyte |
128 | Paragraph |
In any group of bits, the rightmost bit is called the low order bit, or the least significant bit. The leftmost bit is called the high order bit or the most significant bit. Bits are numbered from right to left, starting with zero. For example, in a byte the least significant bit is bit 0. The most significant bit is bit 7.
Similarly, words and larger groups of bits have the least and most significant bytes. Doublewords have least and most significant words.
| Home Page
| Beginners
| Advanced
| Links
| Downloads
| Books |
| C Tutorial
| HYPERSearch
| Guestbook
| Feedback |