Binary : Binary
Binary, decimals and hexadecimals
This section deals with:
One reason why bits are grouped into bytes is that this makes it easy to use them to represent numbers.
Binary numbers have various uses in electronics and communications. For example, they can be used in control programs to set all the output signals from a PIC or an interface with a single command, rather than having to set the bits one at a time. This can simplify programs.
Of course, an individual bit can only represent a ‘1’ or a ‘0’. But, just like ‘normal’ digits, groups of binary digits can represent much larger values. The way this is done in binary numbers is to make each digit worth twice as much as the digit to its right. (In the decimal system each digit worth ten times as much as the digit to its right)
So, for example, the binary number 1101 is worth 13 in ordinary decimal numbers.
A byte has eight bits, so the maximum value of a byte is 1111 1111 (in binary) = 255 (in decimal). This is shown in the following table:
If you have a PC available, there is an easy way to convert from binary to decimal and back again.
Open the calculator that comes with Windows and select the Scientific option in the View menu. To convert from binary to decimal, click on the ‘Bin’ radio button, enter the number is binary and then click on the ‘Dec’ button.
If you want to go from decimal to binary - do the reverse.
There is also a binary and decimal converter on the web.
Because binary digits are rather longwinded, and converting from binary to decimal is tedious, designers sometimes use ‘hexadecimal’ numbers.
A single hexadecimal digit represents four binary digits. So, a hexadecimal digit has to cover the binary numbers 0000 (= 0 in decimal) to 1111 (= 15 in decimal). The way this is done is to use the usual decimal digits for the numbers from 0 to 9 (i.e. from 0000 to 1001 in binary) and then to use the letters:
A byte has eight bits, so the maximum value of a byte is 1111 1111 (in binary) = FF (in hexadecimal).
The calculator in Windows can also be used for conversion to and from hexadecimal.
Hexadecimal numbers are not as useful to pupils as binary, but you may encounter them in occasional magazine articles or data sheets.