Binary and Hexadecimal Numbers
Binary and hexadecimal numbers let you write the same quantity using different sets of digits. You meet binary when reading stored values and hexadecimal when reading compact identifiers or addresses. Octal provides another useful grouping of binary digits. Here, all values are unsigned whole numbers. Changing the representation changes how you write a number, not the quantity it represents.
Digits and place value
The base of a number system determines its permitted digits and the factor between neighbouring place values. In positional notation, the rightmost whole-number position has weight one. Moving one position left multiplies the weight by the base.
System | Base | Permitted digits | First four weights from the right |
|---|---|---|---|
Binary | 2 | 0, 1 | 1, 2, 4, 8 |
Octal | 8 | 0–7 | 1, 8, 64, 512 |
Decimal | 10 | 0–9 | 1, 10, 100, 1000 |
Hexadecimal | 16 | 0–9, A–F | 1, 16, 256, 4096 |
In hexadecimal, A, B, C, D, E and F represent the decimal digit values 10 through 15. A bit is one binary digit, either 0 or 1. A subscript identifies the base: 1012 and 10110 represent different quantities.
For a whole number with k digits, the governing place-value rule is
Here, b is the base, di is the digit value in position i, and positions are counted from zero at the right.
Example: The binary number 101101102 represents
Converting to and from decimal
To convert into decimal, multiply each digit value by its place weight and add the contributions. This procedure works in every base, including hexadecimal: B616=11(16)+6=18210.
To convert a decimal whole number into another base, divide repeatedly by the target base. Record each remainder, then continue with the whole-number quotient until it becomes zero. Read the remainders from last to first. The first remainder belongs to the rightmost position because it counts the units left after removing complete groups of the base.
For decimal 182 converted to hexadecimal, 182=11(16)+6 and 11=0(16)+11. Reading the remainders backwards gives digit values 11 and 6, written B6. A remainder of 11 becomes the single hexadecimal digit B, not the two characters 11.
Moving directly between binary, octal and hexadecimal
Because 16=24, each hexadecimal digit corresponds to exactly four binary digits. Because 8=23, each octal digit corresponds to exactly three binary digits. Group binary digits from the right-hand end. If the leftmost group is incomplete, add leading zeros to complete it.
For the reverse conversion, replace each hexadecimal digit with four bits or each octal digit with three bits. Keep zeros inside the resulting number. Leading zeros may be removed when no fixed width is required.
A fixed width limits the largest value available. With n unsigned bits, the smallest value is zero and the largest has every bit equal to one:
There are 2n distinct patterns, including the pattern representing zero.
What to remember
- Use the base to determine valid digits and place weights.
- Convert to decimal by adding weighted digit values.
- Convert from decimal by repeated division and reversed remainders.
- Group binary digits in fours for hexadecimal or threes for octal.
- Distinguish a number's value from the number of digits used to display it.
Example: One sensor identifier in three bases
A maintenance register lists a sensor's whole-number identifier as 23710. A technician must enter the same identifier into three fields that use binary, hexadecimal and octal notation. The identifier has no units, and the fields do not require a fixed number of digits.
a) Write the identifier in binary.
Start with the greatest power of two that does not exceed 237, which is 128. Subtract selected powers until the remainder is zero. After subtracting 128, the remainder is ________.
The remainder after selecting 128, 64 and 32 is ________. The next weight, 16, is too large, so its digit is zero. Continue with the smaller weights:
The weight 2 is not used. Reading the digits for weights 128, 64, 32, 16, 8, 4, 2 and 1 gives 1,1,1,0,1,1,0,1. Check by adding the selected weights:
The binary identifier is 111011012.
b) Use the binary representation to write the identifier in hexadecimal.
Group the binary digits in fours, starting from the right. Each group becomes one hexadecimal digit.
The first group has decimal value ________, since 8+4+2=14, so its hexadecimal digit is E. The second group has value 8+4+1=13, so its digit is D.
Check the resulting representation using hexadecimal place values:
The hexadecimal identifier is ED16.
c) Use the binary representation to write the identifier in octal.
Octal uses groups of three binary digits. Padding means adding leading zeros to complete the leftmost group without changing a whole number's value. One leading zero produces the nine-digit string ________.
Keep the groups aligned from the right:
The groups have values 2+1=3, 4+1=5 and 4+1=5. These are the octal digits. Verify them using powers of eight:
The octal identifier is 3558.
A network technician's notes use several standard words for parts of a binary numeral such as 101100102. Match each term on the left with the description that defines it.
A group of eight binary digits, the usual unit for addressing memory
The leftmost digit of a binary numeral, carrying the largest place weight
A group of four binary digits, which corresponds to exactly one hexadecimal digit
A single digit in base two, either 0 or 1
The rightmost digit of a binary numeral, whose place weight is 20=1
The count of distinct digit symbols a positional system uses, which is also the factor between neighbouring place weights
Bit
Least significant bit
Radix
Nibble
Byte
Most significant bit
A device label records the same whole-number identifier as 125710 and 4□916. The square stands for one missing hexadecimal digit. What decimal value does that digit represent? Give an exact integer with no units.