Search ECT

# Binary : Binary

This section deals with:

• decimal to binary conversion and vice versa
• decimal to hexadecimal conversion and vice versa

### Binary Numbers

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.

 Digit value 8 4 2 1 Binary number 1 1 0 1 Decimal equivalent 8 + 4 + 0 + 1 = 13

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:

 Digit value 128 64 32 16 8 4 2 1 Binary number 1 1 1 1 1 1 1 1 Decimal equivalent 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

If you have a PC available, there is an easy way to convert from binary to decimal and back again.

Screenshot of Windows Calculator

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 for 10 (1010 in binary)
• B for 11 (1011 in binary)
• C for 12 (1100 in binary)
• D for 13 (1101 in binary)
• E for 14 (1110 in binary)
• F for 15 (1111 in binary)

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.

These are the details: