Binary and Hexadecimal: Convert Values and Check the Place Weights


Binary and hexadecimal describe values using different place weights. A conversion changes the notation, not the quantity. The safest method is to label the base, write the relevant weights, perform the conversion and check the result by returning to decimal.

These worked examples of binary and hexadecimal conversion use unsigned whole numbers that fit in eight bits. An eight-bit unsigned value lies from 0 to 255. We use leading zeros when an eight-bit answer is requested. Signed representations, fractions, two’s complement, floating point and arithmetic overflow are separate topics and are not assumed here.

Start with the base and valid digits

The three positional number systems used in this lesson.
System Base Valid digits Rightmost place weights
Decimal 10 0 to 9 1, 10, 100
Binary 2 0 and 1 1, 2, 4, 8
Hexadecimal 16 0 to 9, then A to F 1, 16, 256

In hexadecimal, A, B, C, D, E and F stand for decimal 10, 11, 12, 13, 14 and 15. Each is one digit, not a two-digit decimal number. The small subscript in 1012 labels its base: it does not multiply the value by two. Without a base label, a string such as “10” is ambiguous in a conversion exercise.

The rightmost whole-number position always has weight one, because the base raised to power zero is one. Moving one position left multiplies the weight by the base. Thus binary weights double, while hexadecimal weights multiply by sixteen. Preserve empty positions with zeros: a zero contributes nothing but keeps neighbouring digits in their proper places.

The eight-bit place-value diagram

Eight-bit place values: decimal 86 in binaryFrom left to right, weights 128, 64, 32, 16, 8, 4, 2, 1 have bits 0, 1, 0, 1, 0, 1, 1, 0. Contributions 0, 64, 0, 16, 0, 4, 2, 0 sum to 86. The binary pattern is 01010110. The article supplies the full native-text place-value table. 2026-10-06T14:45:09.197304 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ Eight-bit place values: decimal 86 = binary 01010110 128 0 0 64 1 64 32 0 0 16 1 16 8 0 0 4 1 4 2 1 2 1 0 0 Weight Bit Value Selected weights: 64 + 16 + 4 + 2 = 86 Each position keeps its weight, including positions containing zero.
Original place-value diagram for 01010110₂. The table below supplies every position, bit and contribution in text.
Reading 01010110₂ as a weighted sum.
Weight Bit Contribution
128 0 0
64 1 64
32 0 0
16 1 16
8 0 0
4 1 4
2 1 2
1 0 0

Worked conversion 1: decimal 86 to eight-bit binary

Consider the weights from 128 down to 1. Decimal 86 is below 128, so the first bit is 0. Use 64, leaving 22. Do not use 32 because it is too large. Use 16, leaving 6; skip 8; use 4, leaving 2; use 2, leaving 0; do not use 1.

The bits are therefore 010101102. Check by adding the selected weights: 64 + 16 + 4 + 2 = 86. The leftmost zero preserves the requested width. The seven-bit writing 10101102 has the same unsigned value but does not display eight positions.

Worked conversion 2: binary 10110101 to decimal

Align 101101012 with weights 128, 64, 32, 16, 8, 4, 2, 1. The one-bits select 128, 32, 16, 4 and 1. Add them: 128 + 32 + 16 + 4 + 1 = 18110. The zeros at weights 64, 8 and 2 contribute nothing.

An estimate offers a useful error check. The leading bit is one, so the value is at least 128. It is an eight-bit unsigned value, so it cannot exceed 255. An answer of 53 would be suspicious because it loses the 128 contribution. Checking a range does not prove the exact answer, but it catches many misplaced-weight errors.

Worked conversion 3: hexadecimal 6D to binary and decimal

One hexadecimal digit corresponds to four binary digits, called a nibble. Since 6 = 4 + 2, its nibble is 0110. Since D means 13 = 8 + 4 + 1, its nibble is 1101. Keeping their order gives 6D16 = 011011012.

Check independently in decimal: 6 × 16 + 13 × 1 = 96 + 13 = 109. The binary check also gives 64 + 32 + 8 + 4 + 1 = 109. Do not write D as the decimal digits “13” and then convert those digits separately: D is one hexadecimal place.

Worked conversion 4: binary 1011010 to hexadecimal

For a whole number, start at the right and group into sets of four: 101 | 1010. Pad only the incomplete leftmost group, giving 0101 | 1010. The groups represent 5 and A, so the answer is 5A16.

The weighted binary sum is 64 + 16 + 8 + 2 = 90. The hexadecimal check is 5 × 16 + 10 = 90. Padding on the right would produce 101101002, whose value is 180, because every original bit moves to a place with twice its old weight. That changes the number rather than merely changing its width.

Worked conversion 5: decimal 202 to hexadecimal

Divide 202 by 16: 202 = 12 × 16 + 10. The quotient 12 becomes C and the remainder 10 becomes A. Therefore 20210 = CA16. Both pieces are below sixteen, so each needs only one hexadecimal digit in this example.

The binary route checks the answer: C becomes 1100 and A becomes 1010, producing 110010102. Its selected weights sum to 128 + 64 + 8 + 2 = 202. Do not report “1210” as the hexadecimal answer: that writes four place positions instead of the required two.

A short binary addition, with every carry explained

Calculate 001101102 + 000110112. Work from the rightmost position. A column sum of two is 102: write 0 and carry 1. A column sum of three is 112: write 1 and carry 1. A carried one belongs in the next column to the left.

Column-by-column addition. Rows run from the rightmost bit towards the leftmost bit.
Weight First bit Second bit Carry in Result bit Carry out
1 0 1 0 1 0
2 1 1 0 0 1
4 1 0 1 0 1
8 0 1 1 0 1
16 1 1 1 1 1
32 1 0 1 0 1
64 0 0 1 1 0
128 0 0 0 0 0

Read the result from weight 128 down to weight 1: 010100012. In decimal, the addends are 54 and 27; their sum is 81. The result has weights 64 + 16 + 1 = 81. It fits within the eight-bit unsigned range used throughout this lesson.

Diagnose a leading-zero and base-label error

A learner writes, “001010 equals decimal 1,010 because the first two zeros can be removed.” Removing leading zeros from an unsigned whole-number representation does preserve its value, but it does not change the base. If the original is 0010102, the value is 8 + 2 = 1010. It becomes 10102, not 101010.

Write the base beside intermediate results as well as the final answer. This prevents “10” from silently switching between decimal ten, binary two and hexadecimal sixteen in the same solution.

Six solved practice tasks

  1. Convert 4510 to eight-bit binary. Use 32 + 8 + 4 + 1. Answer: 001011012. The selected weights total 45.
  2. Convert 100110012 to decimal. Add 128 + 16 + 8 + 1. Answer: 15310. Remember that the second bit, weight 64, is zero.
  3. Convert B616 to binary. B is 11, giving 1011; 6 gives 0110. Answer: 101101102. Check: 11 × 16 + 6 = 182.
  4. Convert 011010012 to hexadecimal. Group 0110 | 1001, giving 6916. Check: 6 × 16 + 9 = 105, equal to 64 + 32 + 8 + 1.
  5. Convert 15610 to hexadecimal. 156 = 9 × 16 + 12. Answer: 9C16. The remainder twelve is C, not the two digits 12.
  6. Add 001001012 and 000101112. Carry from the units column through the next two positions as needed. Answer: 001111002. Decimal check: 37 + 23 = 60 = 32 + 16 + 8 + 4.

Convert storage units without changing their convention

The number-conversion examples above use bits to represent values. Capacity asks how much data can be held. Use one byte (B) = eight bits here; a four-bit nibble is half a byte. Uppercase B means bytes, while the word “bit” means bits. A value’s numeric size is different from the storage allocated to encode it: the value 7 can be shown in an eight-bit field even though its shortest unsigned binary form is 111.

Explicit capacity conventions for every exercise in this section
Unit Exact bytes Convention
1 kB 1,000 Decimal kilo
1 MB 1,000,000 Decimal mega
1 GB 1,000,000,000 Decimal giga
1 KiB 1,024 Binary kibi
1 MiB 1,048,576 = 1,024 KiB Binary mebi
1 GiB 1,073,741,824 = 1,024 MiB Binary gibi

Some older exercises write KB while intending 1,024 bytes. Do not infer that convention from the letters alone: read or state the exercise’s definition. The explicit kB/KiB distinction here follows the NIST binary-prefix explanation. It is not a claim that all software labels capacity consistently.

Worked conversion using actual prepared files

The prepared LDP01 v1.0 learner PDF contains 102,626 bytes and its separate answer-guide PDF 49,254 bytes. Their inspected pair totals 151,880 bytes. These are existing local demonstration artifacts, not hosted downloads. Decimal size = 151,880 ÷ 1,000 = 151.88 kB. Binary size = 151,880 ÷ 1,024 = 148.3203125 KiB, or about 148.32 KiB to two decimals. Both describe exactly the same bytes; the smaller displayed number does not mean data vanished.

At eight bits per byte the same pair contains 151,880 × 8 = 1,215,040 bits. A stipulated ideal transfer rate of 8,000,000 bits per second gives 1,215,040 ÷ 8,000,000 = 0.15188 seconds before overhead, latency or interruptions. This is only a dimensional calculation, not a prediction of anyone’s connection or download time.

Worked capacity decision with a boundary check

A fictional device has exactly 2 MiB of free usable space, and each unchanged file is 640 KiB. Convert 2 MiB to 2,048 KiB. Three files require 1,920 KiB, leaving 128 KiB; four require 2,560 KiB and exceed capacity by 512 KiB. Ignore filesystem metadata and compression only because the task explicitly does so. Do not divide 2 by 640 before matching units.

Checked transfer tests; answers use the declared conventions
Task Working Expected result
Convert 128 bits to bytes 128 ÷ 8 16 B
Compare 2 MB and 2 MiB 2,097,152 − 2,000,000 2 MiB is 97,152 B larger
Independent task: 3,072 KiB to MiB 3,072 ÷ 1,024 3 MiB
Independent task: four 250 kB files in 1 MB 4 × 250,000 = 1,000,000 Exact fit; 0 B left in the no-overhead model
Empty file in the arithmetic model 0 × 8 0 data bits; no claim of zero filesystem overhead
Negative capacity supplied A data capacity cannot be negative in this exercise Invalid input; request a corrected figure

The retained hardware explanation separates active working data in RAM from saved data on persistent storage. Converting both capacities into bytes does not make their functions interchangeable. A program’s RAM need cannot be satisfied merely by adding an equally sized storage drive.

Frequently asked questions

Why is hexadecimal convenient for binary?
Each hexadecimal digit corresponds exactly to four bits, so grouping is direct without first converting the whole number to decimal.
Which side do I group from?
For the whole numbers here, group from the rightmost bit. Pad an incomplete leftmost group with leading zeros.
Do leading zeros change an unsigned value?
No. They change the displayed width but contribute zero. Zeros appended on the right generally change the value.
Is 102 a valid binary number?
No. Binary permits only 0 and 1 as digits. The digit 2 signals a notation or transcription error.
What does F mean in hexadecimal?
F represents decimal fifteen as one digit. The next value, decimal sixteen, is written 10 in hexadecimal.
Why is binary 1 + 1 written 10?
The total is decimal two. Binary has no digit 2, so the sum uses one two and zero ones.
Does every eight-bit pattern here represent a positive number?
The lesson uses unsigned values, including zero. Signed interpretations require a separately stated representation and are outside these examples.

The authors’ Computer Systems chapter preview hosted by Carnegie Mellon provides background on hexadecimal notation. Continue with the Computer Studies topical revision collection; resource contents may require membership. Every worked number and practice task above was created for this lesson.