Binary & data representation
This course explains how computers store data as 0s and 1s, starting from transistors and the binary system. It covers bits, bytes and the difference between KB and KiB, binary addition, bitwise operations, shifts and two's complement. It shows how ASCII and UTF-8 turn text into bytes, why floats cannot hold most decimals precisely, and how hexadecimal writes binary compactly, including CSS colors. The last lesson connects these ideas to Ruby strings, symbols, integers, ActiveRecord column types and pack and unpack.
What you'll learn
- ✓Counting and converting numbers in binary, decimal and hexadecimal
- ✓Bits, bytes and the difference between decimal and binary size units
- ✓Bitwise operations, bit shifts, two's complement and integer overflow
- ✓How ASCII, Unicode and UTF-8 encode text, and how to fix mojibake
- ✓Why floats are approximate and how to store money with decimal or integer cents
- ✓How Ruby objects, strings, symbols and ActiveRecord columns map to bytes
What is binary?
You count using ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. This is the decimal system (base-10), and you use it because you have ten fingers.
Read the full lesson free →Curriculum
7 lessonsWhat is binary?
Why computers use base-2, how binary columns work, and how to convert numbers in Ruby and by hand.
Bits and bytes: units of data
Bits, bytes, KB versus KiB, bits versus bytes in networking, and how Ruby measures string and object size.
Binary arithmetic
Binary addition, AND, OR, XOR and NOT, bit shifts, two's complement for negatives, and integer overflow.
Representing text: ASCII & UTF-8
How ASCII and UTF-8 map characters to bytes, why length differs from bytesize, and common encoding bugs.
Representing numbers: integers & floats
Integer sizes, IEEE 754 floats, why 0.1 + 0.2 differs from 0.3, and safe ways to store money.
Hexadecimal & colors
Hexadecimal as compact binary, hex literals in Ruby, CSS colors with alpha, and URL encoding with hex bytes.
Data representation in Ruby
How Ruby exposes binary data through bases, string encodings, object sizes, symbols, ActiveRecord types and pack/unpack.