Binary & Logic: How Computers Count and Decide
Understand bits and bytes, convert between decimal, binary and hexadecimal, add in binary, and build truth tables for AND, OR, NOT and XOR — the foundations of every digital circuit and every if-statement.
What you will learn
- Explain place value in base 2 and base 16
- Convert numbers between decimal, binary and hexadecimal
- Add binary numbers and recognise overflow
- Evaluate logical expressions with truth tables
- Apply De Morgan's laws
Prerequisites
- Whole-number arithmetic and powers
Learning path
1 Binary numbers
2 Boolean logic
Practical project: Build a binary toolkit
- Write a function
toBinary(n)in JavaScript or Python that uses the division method (no built-in conversion). Test it on 0, 1, 45, 255 and 1024. - Write
fromBinary(s)that adds place values. Check thatfromBinary(toBinary(n)) === nfor n = 0 … 1000. - Write
truthTable(f, n)that prints the table of any boolean function with n inputs. - Use it to verify both De Morgan laws and A OR (A AND B) = A.
- Explain in a short paragraph why one hex digit is exactly four bits.
References
Related courses
JavaScript Fundamentals
The language of the web, from the ground up: values, types and operators, control flow, functions and arrow functions, arrays with…
Python Fundamentals
Learn to program with Python from scratch: values and variables, decisions, loops, lists, dictionaries, strings, functions and error handling. Every…
DC Circuits and Ohm's Law
The foundation of electrical engineering and electronics: voltage, current, resistance, power and energy; series and parallel circuits, Kirchhoff's…