Electronics & Circuits · Study deck

Binary Number Systems

Picture a pressure alarm stored as eight bits.

Voltage Vera is your guide for this deck.

analogdigitalbinary
Voltage Vera, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Convert Binary Numbers: Translate between decimal and binary number systems using place-value decomposition
  • Apply Powers of 2: Calculate ADC resolution ranges from bit depth
  • Interpret Place Values: Use positional notation in base-2 arithmetic
  • Analyse Floating Point: Explain IEEE 754 representation and identify its precision limitations
Number 37 in binary representation
Number 37 in binary representation
iotclass.org

Major section

Start Simple

The same row can mean a value, several flags, or part of a signed number.

  • The hardware contract must say which meaning is correct.
  • An analog-to-digital converter is a circuit that turns a changing voltage into a number.
  • ADC is its short name.
  • This runway does not prove measurement accuracy or every number format.

Key terms

Binary
Binary means writing numbers with only zero and one, where each place has a power-of-two value.
iotclass.org

Major section

Phoebe's Field Notes: How Many Bits Does A Reading Actually Need

The mathematical gist: To resolve a smallest change Δ\DeltaΔ across span VFSV_{FS}VFS​, require 2N≥VFS/Δ2^N\ge V_{FS}/\Delta2N≥VFS​/Δ, hence Nmin=⌈log⁡2(VFS/Δ)⌉N_{min}=\lceil\log_2(V_{FS}/\Delta)\rceilNmin​=⌈log2​(VFS​/Δ)⌉.

  • Resolving 1% of a 50 mV conditioned span needs 7 bits; leaving that signal on a bare 5 V range needs 14 bits.

Let Eddie turn repeated halving into a range-aware bit budget.

iotclass.org

Major section

For Kids: Meet the Sensor Squad!

But your feelings are analog - smooth like sliding down a slide." This was a big problem!

  • Analog and digital are like the difference between a slide (smooth) and stairs (steps)!
  • I can only work with exact step numbers, like climbing stairs.
  • The Sensor Squad's translation team was complete!
ADC conversion from a physical quantity through a sensor and analog voltage to a bounded digital code interpreted by software
ADC conversion from a physical quantity through a sensor and analog voltage to a bounded digital code interpreted by software
iotclass.org

Major section

For Kids: Meet the Sensor Squad! (continued)

But I can make my stairs have MORE steps - instead of big steps like 20, 21, 22, I can use tiny steps like 20.0, 20.1, 20.2.

  • Temperature Terry had a problem. "Max, I can feel temperatures that go smoothly from cold to hot - like 20.1, 20.2, 20.3 degrees.
  • He's a translator!" ADC Andy arrived with a big smile. "I can help!
  • The more steps I use, the closer I get to Sammy's smooth feelings!" Now Sammy could measure temperatures, Andy would translate them into step-numbers, and Max could process them.
Number 37 binary conversion process
Number 37 binary conversion process
iotclass.org

Major section

Getting Started: Analog vs Digital

The analog trace can occupy any intermediate voltage, while the digital trace can occupy only one of the four pictured step levels.

  • The left-hand trace has effectively infinite possible values; the right-hand trace assigns each sample to one of 2n2^n2n fixed levels.
  • Everything we want to measure is analog, but computers only understand digital!
  • Each arrow changes the quantity or its representation.

Why it matters

That loss of intermediate values is quantisation, and increasing nnn reduces the voltage interval represented by each step.

Analog vs Digital Signals: Continuous Ramp vs Discrete Steps
Analog vs Digital Signals: Continuous Ramp vs Discrete Steps
iotclass.org

Major section

Binary Number System

Each added bit has two states and doubles the combinations, so four bits produce 24=2×2×2×2=162^4=2\times2\times2\times2=1624=2×2×2×2=16 possible values.

  • Eight bits similarly provide 256 values numbered 0 through 255.
  • This distinction matters for ADC work: 2n2^n2n counts the available quantization levels, while 2n−12^n-12n−1 is the largest code.
  • Because an unsigned code begins at zero, those values are numbered 0 through 15 rather than 1 through 16.

Why it matters

Because an unsigned code begins at zero, those values are numbered 0 through 15 rather than 1 through 16.

Powers of 2 and binary place values
Powers of 2 and binary place values
iotclass.org

Major section

ADC Resolution vs Range

The Mistake: Assuming that a "12-bit ADC" can measure 12 volts, or that increasing bit depth extends the measurable voltage range.

  • For a 12 V input, the pin is 12/6.6 = 1.818 V; a calibrated 1.818 V reading gives 12.0 V.
  • Raw code alone is not a 3.3 V/4095 voltmeter.
  • They expected accurate readings because "12-bit should handle 12 volts." The ESP32 immediately damaged because its maximum input is 3.3V, not 12V.
iotclass.org

Deck summary

Key takeaways

The same row can mean a value, several flags, or part of a signed number.

  • The mathematical gist: To resolve a smallest change Δ\DeltaΔ across span VFSV_{FS}VFS​, require 2N≥VFS/Δ2^N\ge V_{FS}/\Delta2N≥VFS​/Δ, hence Nmin=⌈log⁡2(VFS/Δ)⌉N_{min}=\lceil\log_2(V_{FS}/\Delta)\rceilNmin​=⌈log2​(VFS​/Δ)⌉.
  • But your feelings are analog - smooth like sliding down a slide." This was a big problem!
  • But I can make my stairs have MORE steps - instead of big steps like 20, 21, 22, I can use tiny steps like 20.0, 20.1, 20.2.
iotclass.org

Retrieval practice

Recall check 1 of 3

Voltage Vera says: answer from memory, then check your reasoning.

Q1Why should you avoid using == to test whether two computed floating-point sensor values are approximately equal?

ASlow comparisons make exact floating-point equality unsuitable in real time.
BRounding in binary floating point makes exact comparison unreliable.
CFloating-point values cannot be compared by any numeric operator.
DCompiler errors prevent exact equality checks on computed sensor values.
Show answer

Answer: B see answers page

Q2What is the decimal value of binary 1101?

ADecimal 11 (binary 1011)
BDecimal 13 (binary 1101)
CDecimal 15 (binary 1111)
DDecimal 9 (binary 1001)
Show answer

Answer: B Answer: B) 13 11012=(1×8)+(1×4)+(0×2)+(1×1)=8+4+0+1=13101101_2 = (1×8) + (1×4) + (0×2) + (1×1) = 8 + 4 + 0 + 1 = 13_{10}11012​=(1×8)+(1×4)+(0×2)+(1×1)=8+4+0+1=1310​.

iotclass.org

Retrieval practice

Recall check 2 of 3

Voltage Vera says: answer from memory, then check your reasoning.

Q3How many different values can a 16-bit ADC represent?

A16,384
B32,768
C131,072
D65,536
Show answer

Answer: D Answer: C) 65,536 Values=2bits=216=65,536Values = 2^{bits} = 2^{16} = 65,536Values=2bits=216=65,536 The actual digital output ranges from 0 to 65,535 (one less than total values).

Q4If you increase an ADC from 10-bit to 12-bit, how much more precise is each voltage step?

A2× more precise (2 more bits = double precision)
B12× more precise (12 bits vs 10 bits)
C1.2× more precise (linear relationship)
D4× more precise (2^2 = 4 times more voltage levels)
Show answer

Answer: D Each additional bit doubles the resolution: 10-bit = 1,024 levels, 12-bit = 4,096 levels.

iotclass.org

Retrieval practice

Recall check 3 of 3

Voltage Vera says: answer from memory, then check your reasoning.

Q5What quantity is being encoded before any binary bit position is interpreted in the 37 example?

ADecimal input: 37
BBit 5 = 1 (value 32)
CBit 2 = 1 (value 4)
DBit 0 = 1 (value 1)
Show answer

Answer: A 37 is the quantity being encoded before any bit position is interpreted.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. B · Due to binary representation limitations, operations like 0.1 + 0.2 may not exactly equal 0.3 in floating-point arithmetic. Use threshold comparison instead: if (abs(a - b) < 0.0001). This is critical for IoT sensor thresholds, PID controllers, and any comparison involving floating-point sensor readings to avoid unpredictable behavior.
  2. B · Answer: B) 13 11012=(1×8)+(1×4)+(0×2)+(1×1)=8+4+0+1=13101101_2 = (1×8) + (1×4) + (0×2) + (1×1) = 8 + 4 + 0 + 1 = 13_{10}11012​=(1×8)+(1×4)+(0×2)+(1×1)=8+4+0+1=1310​.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. D · Answer: C) 65,536 Values=2bits=216=65,536Values = 2^{bits} = 2^{16} = 65,536Values=2bits=216=65,536 The actual digital output ranges from 0 to 65,535 (one less than total values).
  2. D · Each additional bit doubles the resolution: 10-bit = 1,024 levels, 12-bit = 4,096 levels.
  3. A · 37 is the quantity being encoded before any bit position is interpreted.
iotclass.org