# Bits, Bytes, and Binary

a temperature sensor. You wired up the LCD, used the programming cable and wrote code
that reads an analog signal from the temperature sensor and converts it to digital value and
continuously updates the LCD. The code you wrote uses the LCD to show the raw value coming
from the analog to digital converter as well as the average temperature in degrees Fahrenheit.
When you wrote the code, there might have been a few things you didn’t understand, like
this expression which tells the analog to digital converter to start a conversion. You
might have been confused because when you are writing the code for embedded systems
you need to have a low level of understanding of what’s going on with the chip, so we need
to understand more about the language of computers, which brings us to why we need to learn about
bits, bytes and binary. In the binary system we only have two symbols,
0 and 1. We have to be able to represent all the numbers using only these two symbols.
Now, in the systems that you’re used to, the decimal system, you have 10 symbols, 0, 1,
2, 3, 4, 5, 6, 7, 8, and 9. I wonder why they chose 10 — seems to be
sort of arbitrary. Luckily, these two systems work in pretty
much the same way. In the decimal system, the one you’re used to, each place is worth
a different power of 10 which means each place is worth 10 times as much as the previous
one, so if I was to put a 7 on the tenth place, and a 5 on the ones place, the number I have
is just 75. If I was to add a 3 in the 100s place, I would have 300 plus 70 plus 5 equals
375. Now, in the binary system, each place is worth a different power of 2 — this is
because we only have 2 numbers to deal with — so each place is worth twice as much as
the previous one. Simply if say 1 in the second place I just have 2, now, if I was to add
a 1 in the third place and 0s everywhere else, I would have 4 plus 2 which equals 6.
Let’s do another example just to get used to binary numbers. Let’s figure out what the
number 011010 its in binary. Now remember, in the binary system, each place is a different
power of 2 so we have 2 to the 0, 2 to the 1, 2 to the 2 and so on which equals to 1,
2, 4, 8, 16 and 32. Now, this means that we have 0 32s plus 1 16 plus 1 8 plus 0 4 plus
1 2 plus 0 1s which equals 16 plus 8 plus 2 is 26.
Now, binary numbers are helpful because inside your microcontroller there are rows and rows
of memory locations. Now in your NerdKits Guide we talked about how can use circuits
to store high or low voltages. Each one of these high or low voltages that we can store,
we call a bit. We put 8 of these together to form a byte. Now notice how if we want
to represent a really large numbers we’re going to need lots and lots of bits. To store
this number for example, we only need 6 bits. Now, if you go back to your NerdKits Guide,
we can understand more about what this statement does. You are seeing ADCSR equal to a binary
number. ADCSR is just a memory location of the chip. This binary number is created using
a shift operator and you are also using the OR operator. You can learn more about both
of these operators in the later NerdKits video. Hopefully, you learned something about how
to represent number in computer science. The same concepts we learned here can be used
to represent numbers in different bases like hexadecimal, which uses 16 symbols to represent