How Computers Read Numbers

One thing that I’ve learned about computer languages is that there’s a hierarchy:

  1. High-level languages (Python) are “interpreted” into
  2. Lower-level languages (C), which are “compiled” into
  3. Assembly, which is “translated” into
  4. Machine code

Machine code is basically 1s and 0s and is mostly incomprehensible. Obviously there are rules and stuff, but it’s twilight zone.

Assembly is a step towards understandability and I’ve happened to find my way to this online book about programming in Assembly.  It’s in here that I’ve learned how computers look at numbers:

Computers use binary values because transistors can only occupy one of two states: 0 volts or 0.5 volts. 0 or 1. But how do you get real numbers from just 0s and 1s? Surprisingly, the answer is exponents:

For each “1” in the binary string, add in 2**n where “n” is the zero-based position of the binary digit. For example, the binary value 11001010 represents:

1*2**7 + 1*2**6 + 0*2**5 + 0*2**4 + 1*2**3 + 0*2**2 + 1*2**1 + 0*2**0
=
128 + 64 + 8 + 2
=
202 (base 10)

So the binary number ‘0’ means you multiply 0*2^0.

The ^0 comes in because it’s the first digit in the sequence.

’00’ would be 0 * 2^1 + 0 * 2^0 = 0.

’10’ would be 1*2^1 + 0*2^0 = 2.

Clever. It’s pretty impressive how exponents can squeeze so much information out of the ordering of 1s and 0s.

I’m not going to bother trying to figure out how they make words out of this mess today.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s