Skip to main content

Bits, Bytes, Hex

Overview

Notes, study and understanding computer science fundamentals around bits, bytes and hex; how memory works, how to read and debug assembly.

Bits, Bytes, Hex

  • 1 bit = 0 or 1 so "1 bit can represent 2 x numbers"
  • 1 byte = 8 bits i.e. 00000000, 00000001 and every combo of 8-bit 0's and 1's
Numbers in 2 bits = 4
00
01
10
11

If we're calculating for 3 bits

Number in 3 bits2 * (No's in 2 bits) = 8
0XXwhere XX is equal to the 2 bit calculation
1XXwhere XX is equal to the 2 bit calculation

If we're calculating for 4 bits

Number in 4 bits2 * (No's in 3 bits) = 16
0XXXwhere XXX is equal to the 3 bit calculation
1XXXwhere XXX is equal to the 3 bit calculation

To summarize the sequence/pattern here:

Rule of 2
  • 1 bit = 2^1 = 2 numbers
  • 2 bit = 2^2 = 4 numbers
  • 3 bit = 2^3 = 8 numbers
  • 4 bit = 2^4 = 16 numbers

N bits = 2^N numbers

How many numbers can 1 byte represent?

N bits = 2^N numbers i.e. 2^8 = 256

binary to decimal

Take this binary number 10011101 and convert to decimal.

Read this as, "left most" position --> 10011101 <-- count positions starting from the "right most" position where the 1 is the "zero position", and moving to the left from there the 0 is the "first" position.

Calculate position

Position is counted starting from the right-most bit, and counting from 'zero'

Put the number veritcally into this table from the "left most" bit at top.

We ONLY do calculations on the 1 bits and skip the 0 bits.

bitcalculationresult
12^7 (7th position)128
06th position but 00
05th position but 00
12^4th position16
12^3 (3rd position)8
12^2 (3rd position)4
01st position but 0
12^0 (zero position)1

The sum = 157 is the decimal representation of 10011101.

Hexadecimal

  • 0...9
  • A (10), B (11), C (12), D (13), E (14), F (15)

Take hex value 0x3EA

bitcalculationresult
33*16^2 (2nd position)3 x (256) = 768
E14*16^1 (1st position)14 x (16) = 224
A10*16^0 (zero position)10 x (1) = 10

The sum = 1002 is the decimal representation of 0x3EA

Resources