Secondary Computer Science / 1.1 Digital Patterns and Number Codes

1.1.2 Reading and Building Binary Values

🔒 Lesson slides are available to signed-in users. Sign in

1.1.2 Reading and Building Binary Values

A parcel-locker controller may store a locker number as a sequence of binary digits. Although the pattern contains only 0s and 1s, each position has a different value. The position of a bit therefore changes its contribution to the complete number.

In this lesson, you will learn how to read a positive binary integer as a denary value and how to build a binary pattern for a given denary value. You will work with fixed-width patterns containing as many as 16 bits.

By the end of this section, you should be able to:

  • identify binary place values as powers of two;
  • convert a positive binary integer into denary;
  • construct a positive binary integer from a denary value;
  • write values using a specified number of bits;
  • check whether a conversion is reasonable and within range.

Different systems, different place values

The value of a digit depends on both the digit itself and its position. In the denary system, positions increase by powers of ten. In binary, positions increase by powers of two.

Denary 十进制: the base-10 number system, using the digits 0 to 9.

Binary 二进制: the base-2 number system, using only 0 and 1.

Place value 位值: the numerical value assigned to a digit position.
System Base Available digits Place values increase by
Denary 10 0–9 Powers of 10
Binary 2 0 and 1 Powers of 2

For example, the denary number 572 contains:

  • 5 hundreds;
  • 7 tens;
  • 2 ones.

A binary pattern works in the same positional way, but its columns have values such as 1, 2, 4, 8, 16 and 32.

Binary place values

Start at the right-hand side with the value 1. Each movement one position to the left doubles the previous value.

Power 27 26 25 24 23 22 21 20
Place value 128 64 32 16 8 4 2 1
Most significant bit 最高有效位: the bit with the greatest place value, located at the left of the pattern.

Least significant bit 最低有效位: the bit with the smallest place value, located at the right of the pattern.

An 8-bit positive binary integer has the place values:

128 · 64 · 32 · 16 · 8 · 4 · 2 · 1

Common mistake

Do not write the place values as 1, 2, 3, 4, 5 and so on. Each binary column is worth twice the column immediately to its right.

Reading a binary value

To convert a positive binary integer into denary, add the place values of the positions containing a 1. Positions containing a 0 contribute nothing.

Worked example: read 01010110

Place value 128 64 32 16 8 4 2 1
Binary digit 0 1 0 1 0 1 1 0
Contribution 0 64 0 16 0 4 2 0

Step 1: identify the active columns

The positions containing 1 have the place values:

64, 16, 4 and 2

Step 2: add their values

64 + 16 + 4 + 2 = 86

Result

010101102 = 8610

Answer-building tip

Show which place values were selected. A visible calculation such as 64 + 16 + 4 + 2 = 86 makes your reasoning clear and gives you a way to check the result.

Building a binary value

To convert a positive denary integer into binary, compare the value with the binary place values from left to right.

  • Write 1 when a place value is needed.
  • Subtract that place value from the remaining amount.
  • Write 0 when a place value is too large.
  • Continue until every position has been considered.

Worked example: represent 173 using 8 bits

Place value Decision Bit Remaining value
128 128 fits into 173 1 173 − 128 = 45
64 64 is greater than 45 0 45
32 32 fits into 45 1 45 − 32 = 13
16 16 is greater than 13 0 13
8 8 fits into 13 1 13 − 8 = 5
4 4 fits into 5 1 5 − 4 = 1
2 2 is greater than 1 0 1
1 1 fits into 1 1 1 − 1 = 0

Reading the completed bits from left to right gives:

17310 = 101011012

Check by converting back

128 + 32 + 8 + 4 + 1 = 173

Common mistake

Do not stop when the remaining value reaches zero. Any unused positions still need to be written as 0 so that the answer contains the required number of bits.

Fixed-width binary patterns

A question or computer system may require a value to use a particular number of bit positions. An 8-bit pattern must contain eight digits, even when the number could be written using fewer digits.

Fixed width 固定位宽: a representation that always uses a specified number of bit positions.

Leading zero 前导零: a zero placed at the left of a number to fill unused positions without changing its value.
Denary value Shortest binary form 8-bit form 16-bit form
6 110 00000110 0000000000000110
57 111001 00111001 0000000000111001
214 11010110 11010110 0000000011010110

The leading zeros do not add any value. They only show the width of the register or representation being used.

Common mistake

Adding zeros to the right changes the value. To preserve the same positive binary value, width is added using zeros on the left.

How much can a fixed number of bits hold?

The largest positive value is produced when every bit is 1. For an n-bit positive binary value, the maximum is:

2n − 1

Width Largest binary pattern Largest denary value
4 bits 1111 15
8 bits 11111111 255
12 bits 111111111111 4095
16 bits 1111111111111111 65535

This page uses the bits only for positive values. A later lesson will introduce a different interpretation for representing negative integers.

Answer-building tip

Check that the denary value fits within the stated width before beginning a conversion. For example, an 8-bit positive value cannot represent a number greater than 255.

Working with values up to 16 bits

The method does not change when more bit positions are used. A 16-bit positive integer uses place values from 32768 down to 1.

Value 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
Bit 1 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1

The pattern above is:

1010011001110101

Its selected place values are:

32768 + 8192 + 1024 + 512 + 64 + 32 + 16 + 4 + 1 = 42613

Therefore:

10100110011101012 = 4261310

Checking a conversion

A quick check can reveal common errors before you finish.

Check How to use it
Convert back Add the selected place values and confirm the original denary number.
Check the width Count the digits and add leading zeros when required.
Check the range Confirm that the value is no greater than 2n − 1.
Check odd or even An odd positive integer ends in 1; an even positive integer ends in 0.
Check place values Confirm that each column doubles as you move left.

Common mistake

The final-bit check only tells you whether the result has the correct odd/even property. It does not prove that every other bit is correct.

Interactive: Binary Place-Value Laboratory

Change the width, load a denary or binary value, and select individual bits. The widget shows how every active bit contributes to the denary total.

Interactive investigation

Build and read positive binary values

Current value 173 10101101
1. Select the number of bits

An 8-bit positive value can represent 0 to 255.

Build from denary

Read a binary pattern

Select any bit to change its state.

2. Explore the bit positions

Selected place values 128 + 32 + 8 + 4 + 1 = 173

Conversion challenge

Ready for a question?

Choose a challenge type.

No challenge has been selected.

Think before calculating

For binary-to-denary conversion, identify the columns containing 1. For denary-to-binary conversion, begin with the largest place value available.

Practice

Core questions

  1. Write the eight place values used by an 8-bit positive binary integer.
  2. Convert 00101101 into denary. Show the selected place values.
  3. Convert 11001010 into denary.
  4. Convert 0000001101011010 into denary.
  5. Write denary 73 as an 8-bit binary integer.
  6. Write denary 156 as an 8-bit binary integer.
  7. Write denary 918 as a 16-bit binary integer.
  8. State the largest positive denary value that can be represented using 12 bits.
  9. Explain why 00000110 and 110 represent the same positive value.
  10. Explain why adding a zero to the right of a positive binary integer usually changes its value.

Extension questions

  1. Convert denary 4097 into a 16-bit binary integer.
  2. Convert 1000000000000001 into denary.
  3. A device identifier must store values from 0 to 700. Explain why 9 bits are insufficient and 10 bits are sufficient.
  4. A student writes 93 as 1011101. Rewrite it as an 8-bit value and explain what was added.
Check the numerical answers
  1. 8-bit place values: 128, 64, 32, 16, 8, 4, 2 and 1.
  2. 00101101 = 32 + 8 + 4 + 1 = 45.
  3. 11001010 = 128 + 64 + 8 + 2 = 202.
  4. 0000001101011010 = 858.
  5. 73 = 01001001.
  6. 156 = 10011100.
  7. 918 = 0000001110010110.
  8. Largest 12-bit positive value: 4095.
  9. 4097 = 0001000000000001.
  10. 1000000000000001 = 32769.
  11. 93 as an 8-bit value is 01011101.

Review

Key ideas

  • Binary place values are powers of two.
  • The rightmost place value is 1.
  • Each movement left doubles the place value.
  • To read binary, add the place values containing 1.
  • To build binary, compare the denary value with each place value.
  • Leading zeros fill unused positions without changing a positive value.
  • An n-bit positive value has a maximum of 2n − 1.
  • The same methods work with patterns containing up to 16 bits.

Quick self-check

  1. Can I write the place values for an 8-bit or 16-bit pattern?
  2. Can I convert binary into denary by adding selected values?
  3. Can I construct a binary value from a denary integer?
  4. Can I use leading zeros to produce the required width?
  5. Can I check that a value fits within the available number of bits?

One-minute exit task

Convert denary 105 into an 8-bit binary integer, and then convert your answer back into denary to check it.