# Collin's Lab: Binary & Hex

## Video

http://youtu.be/jvx-NrILgpE

Decimal isn't the only way to represent a value - get acquainted with Binary & Hexadecimal, two very important numeral systems often found lurking within the depths of technology.

# Collin's Lab: Binary & Hex

## Transcript

In code, you’ll often see number values&nbsp;written out something like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/018/974/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v3-hex1.jpeg?1408572560)

or maybe even this …

![](https://cdn-learn.adafruit.com/assets/assets/000/018/954/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-6.jpeg?1408571032)

In both cases, they’re describing the number we commonly&nbsp;refer to as two hundred and fifty.

So why don’t programmers just write “250”?

Well, the answer lies deep within the nature of digital electronics. &nbsp;

But first, it helps to get an objective idea of how the system we already know works.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/955/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-11.jpeg?1408571062)

Decimal is a base-10 numeral system.

That means it uses 10 different character symbols to represent numeric values -

0, 1, 2, 3, 4, 5, 6, 7, 8, & 9

A single Decimal digit can represent a maximum value of nine,&nbsp;one more than that

and we have to add another digit to the left of the original

![](https://cdn-learn.adafruit.com/assets/assets/000/018/956/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-12.jpeg?1408571088)

Decimal is a fine system, quite popular in fact.

Why - there it is on the top of my computer keyboard.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/957/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-13.jpeg?1408571113)

But - the computer itself doesn’t “think” in Decimal.

It stores values as electrical charges&nbsp;that can be measured as either Low or High, Off or On …&nbsp;&nbsp;zero or one.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/958/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-14.jpeg?1408571124)

This system is known as “Binary”,

and in binary, each digit is known as a bit.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/959/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-15.jpeg?1408571139)

![](https://cdn-learn.adafruit.com/assets/assets/000/018/960/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-16.jpeg?1408571168)

A bit can hold a maximum value of 1,&nbsp;in order to represent more than 1 we need to add another bit. &nbsp;

So a 2 in binary looks like this …

![](https://cdn-learn.adafruit.com/assets/assets/000/018/961/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-17.jpeg?1408571184)

and a three in binary looks like this …

![](https://cdn-learn.adafruit.com/assets/assets/000/018/975/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v3-hex1-1.jpeg?1408572645)

As we keep counting up to ten,&nbsp;you’ll notice that binary uses up a lot more space&nbsp;compared to good old decimal notation.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/962/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-19.jpeg?1408571196)

And that’s just a 4-bit value,&nbsp;most computers nowadays work with binary values of 32-bit length …

Some even use 64-bit values …

At this point, even if we displayed these values in decimal notation,&nbsp;they’re just ridiculously long and unwieldy.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/963/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-20.jpeg?1408571209)

So when writing code, it’s helpful to have a more convenient way to represent them.

And that’s where “Hexadecimal” notation comes in handy.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/964/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-21.jpeg?1408571220)

Hexadecimal, or simply “hex” as it’s known to friends,&nbsp;uses 16 characters to represent a number value.

Like decimal, it uses the classics - 0,1,2,3,4,5,6,7,8, & 9

But It also uses letters, to represent values 10 through 15 -&nbsp;like so …

![](https://cdn-learn.adafruit.com/assets/assets/000/018/965/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-23.jpeg?1408571240)

![](https://cdn-learn.adafruit.com/assets/assets/000/018/966/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-25.jpeg?1408571256)

Because of those extra characters,&nbsp;hexadecimal notation takes up less space in text

Making it easier for us humans to type out or even simply remember a specific value.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/967/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-26.jpeg?1408571266)

Oh but wait - that’s not all. &nbsp;Hex also syncs up nicely with the way we group Binary bits.

In Binary - a group of four bits is called a “nybble”

and a nybble can conveniently be represented&nbsp;by a single character in hexadecimal.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/968/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-27.jpeg?1408571278)

![](https://cdn-learn.adafruit.com/assets/assets/000/018/969/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2.jpeg?1408571474)

And 8 bits in Binary, which is called a byte,&nbsp;can be represented using only 2 hex characters.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/970/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v3-1.jpeg?1408571500)

![](https://cdn-learn.adafruit.com/assets/assets/000/018/971/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v3-2.jpeg?1408571512)

In order to clearly specify when we’re using hexadecimal in code,&nbsp;we add a “0x” at the beginning of the value.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/972/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v3-3.jpeg?1408571523)

But in the end - no matter what system we use to represent a value in code,&nbsp;it’ll always be converted to binary & use the same amount of space within digital memory.

So regardless of what we see on the screen, underneath it all - its bits all the way down.

![](https://cdn-learn.adafruit.com/assets/assets/000/018/973/medium800/collin_s_lab_Collins_Lab-Binary_and_Hex-v2-32.jpeg?1408571540)

# Collin's Lab: Binary & Hex

## Learn More

# Comparison
To get a clear idea of how binary, decimal, and hexadecimal compare - check out the table below:

# Converters
There are a number of great tools on the web which allow you to convert between binary, decimal, and hexadecimal. &nbsp;Here's just a few:

## Mobile

[Circuit Playground for iOS](https://itunes.apple.com/us/app/circuit-playground/id492487671)

[Dec&nbsp;Hex Bin ASCII Converter&nbsp;for Android](https://play.google.com/store/apps/details?id=guy.example.dechex&hl=en)

## Web

[Math is Fun Converter](http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html)

## Desktop

[HexDecBin for OSX & Win32](http://malarkeysoftware.com/projects.html#HexDecBin)


## Featured Products

### Blue 7-segment clock display - 0.56" digit height

[Blue 7-segment clock display - 0.56" digit height](https://www.adafruit.com/product/812)
Design a clock, timer or counter into your next project using our pretty 4-digit seven-segment display. These bright crisp displays are good for adding numeric output. Besides the four 7-segments, there are decimal points on each digit and an extra wire for colon-dots in the center (good for...

In Stock
[Buy Now](https://www.adafruit.com/product/812)
[Related Guides to the Product](https://learn.adafruit.com/products/812/guides)
### Membrane 3x4 Matrix Keypad + extras

[Membrane 3x4 Matrix Keypad + extras](https://www.adafruit.com/product/419)
Punch in your secret key into this numeric matrix keypad. This keypad has 12 buttons, arranged in a telephone-line 3x4 grid. It's made of a thin, flexible membrane material with an adhesive backing (just remove the paper) so you can attach it to nearly anything. The keys are connected into...

In Stock
[Buy Now](https://www.adafruit.com/product/419)
[Related Guides to the Product](https://learn.adafruit.com/products/419/guides)
### Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack - Yellow

[Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack - Yellow](https://www.adafruit.com/product/879)
What's better than a single LED? Lots of LEDs! A fun way to make a small display is to use an [8x8 matrix](https://www.adafruit.com/category/37_88) or a [4-digit 7-segment display](https://www.adafruit.com/category/37_103). Matrices like these are...

In Stock
[Buy Now](https://www.adafruit.com/product/879)
[Related Guides to the Product](https://learn.adafruit.com/products/879/guides)
### TIMESQUARE DIY Watch Kit - Red Display Matrix

[TIMESQUARE DIY Watch Kit - Red Display Matrix](https://www.adafruit.com/product/1106)
Show up stylish AND on time to any event with this awesome looking DIY watch. We have a few watch kits here at Adafruit but we finally have one that looks good and fits well, even for ladies and kids and others with smaller wrists and hands. Its got an 8x8 bit matrix display and a repurposed...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1106)
[Related Guides to the Product](https://learn.adafruit.com/products/1106/guides)
### Medium 16x32 RGB LED matrix panel - 6mm Pitch

[Medium 16x32 RGB LED matrix panel - 6mm Pitch](https://www.adafruit.com/product/420)
Bring a little bit of Times Square into your home with this 16 x 32 RGB LED matrix panel. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked really cool so we...

In Stock
[Buy Now](https://www.adafruit.com/product/420)
[Related Guides to the Product](https://learn.adafruit.com/products/420/guides)
### Miniature Keyboard- Microcontroller-Friendly PS/2 and USB

[Miniature Keyboard- Microcontroller-Friendly PS/2 and USB](https://www.adafruit.com/product/857)
Add a typing interface to your project with this microcontroller-friendly miniature keyboard. We found the smallest PS/2+USB keyboard available, a mere 8.75" x 4.65" x 0.6" (220mm x 118mm x 16mm)! It's small but usable to make a great accompaniment to either a...

Out of Stock
[Buy Now](https://www.adafruit.com/product/857)
[Related Guides to the Product](https://learn.adafruit.com/products/857/guides)

## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [Mindfulness Clock OF DOOM](https://learn.adafruit.com/mindfulness-clock-of-doom.md)
- [CircuitPython Hardware: LED Backpacks & FeatherWings](https://learn.adafruit.com/micropython-hardware-led-backpacks-and-featherwings.md)
- [Arduino GPS Clock](https://learn.adafruit.com/arduino-clock.md)
- [Tap Tempo Trinket](https://learn.adafruit.com/tap-tempo-trinket.md)
- [Personalized NextBus ESP8266 Transit Clock](https://learn.adafruit.com/personalized-esp8266-transit-clock.md)
- [Trinket React Counter](https://learn.adafruit.com/trinket-react-counter.md)
- [Fidget Spinner Tachometer](https://learn.adafruit.com/fidget-spinner-tachometer.md)
- [DeLorean Time Circuit](https://learn.adafruit.com/delorean-time-circuit.md)
- [Raspberry Pi Physical Dashboard](https://learn.adafruit.com/raspberry-pi-physical-dashboard.md)
- [LED Backpack Displays on Raspberry Pi and BeagleBone Black](https://learn.adafruit.com/led-backpack-displays-on-raspberry-pi-and-beaglebone-black.md)
- [Trash Panda](https://learn.adafruit.com/trash-panda-circuit-python-crickit.md)
- [Getting Started With Steven Universe](https://learn.adafruit.com/getting-started-with-steven-universe.md)
- [Adafruit New York and NYC DOE vendor information ](https://learn.adafruit.com/educational-orders-for-educators-based-in-new-york.md)
- [Black Lives Matter Education & Workshop Kit](https://learn.adafruit.com/black-lives-matter-badge.md)
