« The MicrocontrollerTruth tables NEVER lie »

1001001 SOS

08/23/08 | by anthony [mail] | Categories: Informative

Binary, the language of machine, but why? In circuitry we have two things we can represent data as. We can use a "on" and a "off" meaning, weather there is current flowing or there is not. Traditionally 1 represents an on, or a high and 0 represents an off or a low. Because of this we work in binary, because there are only two numbers in that system 0 and 1.

Number systems

We work with the decimal system which has values 0-9. This was primarily done more than likely because we have 10 digits which we've used over the centuries to count :D (now if we only counted fingers and not digits we'd be perfectly happy with octal). Each digit in a number represents the base to a power starting at 0 and ending at infinity. To put this to perspective lets look at the number 142. When we break 142 apart we get:
1 4 2
1x10^2 + 4X10^1 + 2X10^0
100+40+2
142

This works for all number systems from binary to hexadecimal and beyond.

Binary

Lets look at a binary number, 1001001 and break it apart.

1 0 0 1 0 0 1
1*2^6 + 0*2^5 + 0*2^4 + 1*2^3 + 0*2^2 + 0*2^1 + 1*2^0
64+0+0+8+0+0+1
73

1001001 is a binary representation of the decimal number 73. Binary doesn't look so daunting anymore does it?

Bits and Bytes

If you've ever been around computers or anything digital you've heard the terms 8-bit 32-bit 64-bit 100 Gigabyte etc. One bit represents one digit of a binary number, either a 1 or a 0. A byte represents 8-bits or two hexadecimal digits(well get on hexadecimal later). Bits and bytes are the main ways computers handle data. Bits being fundamental and bytes being a way to organize bits in a way that they're useful. You cant hold that much information with a bit, however with a byte you can hold up to 256 values (2^8)

Hexadecimal

Even though bits are fundamental we are going to be working with hexadecimal. As you can see, to represent large numbers in binary can get rather confusing. We use hexadecimal to bring things down to size and make code and large registers more manageable. Hexadecimal is a number system based on base 16. If you noticed, 16 is a power of two thus every 4 digits in binary represent 1 hexadecimal digit. We note that a number is hexadecimal with the prefix "0x" or the suffix "h." One thing you might be wondering is how do you represent numbers greater than 9 without using two digits? Simple, we use letters. In hexadecimal we use the number 0-9 and the letters A-F (10-15). So the hexadecimal number 0xB is 11 in decimal and 1011 in binary.

Expanding Hexadecimal

So lets do a quick exercise to see how hexadecimal truly works. Lets start with 0x5FB

To convert this to binary we break it down digit by digit starting with the first.

0xB in binary is 1011. The second digit 0xF is 1111 in binary and 0x5 is 0101 in binary.

We put this all together and get 01011111011. Because hexadecimal is based on a number that is a power of 2, we can work with numbers like this.

Expanding it to decimal isn't all that hard either, however a calculator would help for those tricky powers of 16.

0x5FB
5*16^2 + 15*16^1 + 11*16^0
1280 + 240 + 11 = 1531

In reality, with a little work and patience working with other number systems will come natural and become easier the more you work with them. With the fundamentals of electronics, semiconductors and these number systems we can finally start looking at the microcontroller.

Permalink

Trackback address for this post

This is a captcha-picture. It is used to prevent mass-access by robots.

Please enter the characters from the image above. (case insensitive)

Array

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.

Please enter the characters from the image above. (case insensitive)

Array
May 2012
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Ads by Google

This blog is dedicated to working with digital circuitry and the use of microcontrollers, small compact computers on a chip. I will be encompassing many techniques to develop projects, tools to use to write and assemble code and i will be sharing any projects i am currently working on. User feedback is a must! I do not know it all, hell im not even that experienced, but without a general place to get all the info needed i find it very hard to get into the world of microcontrollers without pursing a CE degree. So come one come all and enter the world of mystery and creativity!

Search

XML Feeds

powered by b2evolution free blog software