Appendix B: hexadecimal numbers

This is a work in progress, and isn't ready to read yet!

If we were to write this all in decimal:

namevalue
Black0
Blue1
Green2
Cyan3
Red4
Magenta5
Brown6
Gray7
DarkGray8
BrightBlue9
BrightGreen10
BrightCyan11
BrightRed12
BrightMagenta13
Yellow14
White15

The code becomes:


# #![allow(unused_variables)]
#fn main() {
slice[1] = 2;
#}

This will work just as well, but we've lost that 0 to let us know that we have black. Furthermore, let's take a look at a more complex version:


# #![allow(unused_variables)]
#fn main() {
slice[1] = 0xFA; // White background, BrightGreen foreground

slice[1] = 250;
#}

0xFA in hexadecimal is 250 in decimal, and it completely loses all of the meaning. We'd have to do the math ourselves to figure out what the color is. Much easier to write it in hexadecimal in the first place.