Hexes and the Magic of 16 🔮

@vaidehijoshi

there are a lot of 

ways to do something

different

you can write numbers in lots of different ways

(it really just depends on how many digits you want to use)

10 digits:

base 10

2 digits:

base 2

/ denary

/ binary

16 digits:

base 16

/ hexadecimal

➡️ 205

➡️ 11001101

➡️ . . . ?

base

are possible per place value

digits

refers to how many 

base 2 base 10 base 16

 




 

A, B, C,
D, E, F

0, 1

0, 1, 2, 3, 4,

5, 6, 7, 8, 9

0, 1, 2, 3, 4,

5, 6, 7, 8, 9

10 digits:

base 10

2 digits:

base 2

/ denary

/ binary

16 digits:

base 16

/ hexadecimal

➡️ 205

➡️ 11001101

➡️ CD

yes, really

➡️ 3 digits in base 10

205

➡️ 8 digits in base 2

➡️ 2 digits in base 16

11001101

205

CD

🆗

but...why does that matter?

🆒

11001101

1

1 bit

1 byte

11001101

8 digits === 1 byte

the fewer the digits,

the more information,

in a tiny amount of space.

💡

2 digits === 1 byte

8 digits === 1 byte

#EC152E

rgb(236, 21, 46)

===

#EC152E

rgb(236, 21, 46)

2E

15

EC

46

21

236

236

3 bytes

21

46

r

g

b

rgb(236, 21, 46)

236

21

46

r

g

b

RGB color model

additive color

theory of trichromatic color vision

#FFFFFF

#000000

#EC152E

2E

15

EC

1 byte

1 byte

1 byte

256 permutations

256

256

256

x

x

=

16,777, 216

any number from 0-255

16 x 16

=

256

hexes are everywhere!

👀

I got 128 problems, but encoding ain’t one

🙈

"Ruby"
52 75 62 79
01010010 01110101 01100010 01111001
0
0
0
0

é

ø

æ

2  = 128
7
2  = 
8
256

magic numbers (hexspeak)

🙊

0xB000 0xDEAD

0xDEADFA11

0xD15EA5E

internet protocol v6

🙉

8 groups of 4 hexes

2 bytes, 16 bits

2b2b:1821:a9ih:0000:0000:ff91:9ab0:1ee3

surprise!

🐒

hexes are in rails, too

type :binary
SecureRandom.hex
app_secret 

#EC152E

111011000001010100101110

abstractions are powerful, necessary tools.

but sometimes they're used as a weapons.

This is worthy of a conference talk? This is week 1 freshman computer science stuff. "

never allow other people to use abstractions to intimidate you.

use them as a tool to empower you.

🔑

abstractions

they're not magic!

abstractions are just that :

💫

understanding abstractions is what            them magical

makes

medium.com/basecs✨

@vaidehijoshi

Hexes and the Magic of Base 16 (Ruby)

By Vaidehi Joshi

Hexes and the Magic of Base 16 (Ruby)

  • 1,653