Classroom Public page

Lab 1.1: Binary by Hand

450 words

~60 minutes. No calculators. Convert decimal to binary and back using the column-weight method. Verify three answers with Python.


Goal: convert 20 numbers between decimal and binary without a calculator. Develop the mental model before using tools.

Estimated time: 60 minutes

Prerequisites: Week 1 lecture (column-weight method and double-and-add method)


Setup

Create a directory for this lab:

mkdir -p ~/fnd-101/lab-1-1
cd ~/fnd-101/lab-1-1

Open a plain text file for your worksheet: lab-1-1-worksheet.txt


Part A: Decimal to binary (10 conversions)

Convert each of the following decimal numbers to binary using the column-weight method. Show your work: write out the column weights (128, 64, 32, 16, 8, 4, 2, 1) and circle or mark which weights contribute.

  1. 7
  2. 13
  3. 25
  4. 42
  5. 64
  6. 100
  7. 127
  8. 128
  9. 200
  10. 255

For each: write "Decimal: X -> Binary: XXXXXXXX" on its own line in your worksheet.


Part B: Binary to decimal (10 conversions)

Convert each of the following binary numbers to decimal. Use the column-weight method (add up the weights where the bit is 1) or the double-and-add method (your choice, but pick one and be consistent).

  1. 00000001
  2. 00001010
  3. 00010000
  4. 00101101
  5. 01000000
  6. 01100100
  7. 01111111
  8. 10000000
  9. 10010110
  10. 11111111

Part C: Python verification

Verify any 3 of your Part A answers using Python. Open a Python interpreter:

python3

For each number you verify:

# Decimal to binary
bin(42)        # returns '0b101010'
# Binary to decimal
int('101010', 2)  # returns 42

Record which 3 you verified and whether your hand calculation matched Python's answer.


Part D: Overflow exercise (no calculator)

Add these two 8-bit binary numbers by hand (as if you were an 8-bit ALU):

  11111111   (= 255 in decimal)
+ 00000001   (= 1 in decimal)

What 8-bit result do you get? What is that result in decimal? What happened to the "extra" bit? Write 2 sentences explaining overflow in your own words.


Expected output / artifact

Your lab-1-1-worksheet.txt should contain:

  • All 20 conversions, Part A and Part B
  • The 3 Python verification outputs (copy-paste from the interpreter)
  • Part D overflow exercise with the result and your 2-sentence explanation

Commit the worksheet to your Git repository:

git add lab-1-1-worksheet.txt
git commit -m "lab-1-1: binary by hand worksheet complete"

Common pitfalls

  • Off-by-one in column weights: double-check that your columns are powers of 2 (1, 2, 4, 8, ...) and that you have exactly 8 columns for an 8-bit number
  • Leading zeros: 7 in decimal is 00000111 in 8-bit binary, not just 111. Include all 8 bits.
  • Part D carry: the carry out of bit 7 is real; it becomes the overflow indicator, not a 9th bit in an 8-bit result

Stretch (optional)

Convert the following decimal numbers to binary and back: 256, 1023, 65535. These exceed 8 bits. How many bits do you need for each? What is the rule for the minimum bit width needed to represent decimal value N?


Lab 1.1 v0.1.