Community

Register

 News

Contact Us

 Reviews

 Guides & Tutorials

 More

HOME  EMBEDDED  HEXADECIMAL AND BINARY NUMBER SYSTEM BASICS FOR EMBEDDED PROGRAMMING

FOLLOW US

Hexadecimal and Binary Number System basics
for Embedded Programming

Search ...

Posted By Umang Gajera Posted date: June 27, 2012 in: Embedded 5 Comments
To get started in Embedded programming following things need to be absolutely clear in our heads:

SUBSCRIBE VIA EMAIL

1. Binary and Hexadecimal Number Systems.
2. Interconversion of Binary and Hexadecimal.

Email Address

3. Bit Level Operations.
4. Pointers , etc..

Subscribe

This tutorial mainly deals with Hexadecimal & Binary Numbering Systems and how to inter-convert
them. This lays the foundation for bit level operations. A complete tutorial for bit level(or bitwise)
operations is located @ www.ocfreaks.com/tutorial-embedded-programming-basics-in-c-bitwiseoperations/.

Numbering Systems & Interconversion
Hexadecimal System / Base-16
The Hexadecimal number system is famous in computing world specially in digital electronics. Its base16 because it uses 16 symbols to represent any number and each digit has an associated multiplication
factor which is a power of 16. Its basically a ‘compact’ numbering system in which few digits are
required to represent a su䏀༠ciently big number as compared to Decimal system. A Hexadecimal
number can readily converted into a binary number and vice-verse. Digits in Hexadecimal systems are
0 to 9 and A,B,C,D,E,F. Each digit in a hexadecimal system can be represented using 4 binary digits. The
order of the digits is in increasing power of 2. We will see Hexadecimal in detail but 䎸껠rst lets go through
Decimal and Binary numbering system & its conversion from binary to decimal.

Decimal System / Base-10
Decimal Numbering system or Base-10(technically) system : This the numbering system we use in our
daily lives. Each digit in a decimal number has an associated ‘weight’ which is nothing but the base
raised to the location number of the digit. Its Base-10 because it uses a combination of 10 ‘symbols’ or
say digits(0,1,2,3,4,5,6,7,8,9) to represent any number.
Consider a decimal number 2734 : By default the digit on extreme RIGHT is called LSD or Least
signi䎸껠cant digit. In out case its ‘4’. While the digit on extreme LEFT is called MSD or Most Signi䎸껠cant Digit
i.e ‘2’ – It most signi䎸껠cant because the change in digit at that location gives big changes in value of the
number. Same argument is applicable for LSD. As you know that Units place has a multiplication factor
of 1 , Tens has that of 10 , Hundreds has that of 100 and soo on.. similar to this we have multiplication
factor for each digit in binary number system as well.

Binary System / Base-2
Binary Numbering system or Base-2 system: It used only 2 symbols(called bits) ‘0’ & ‘1’ to represent any
number. On this Numbering or Counting System is computer understandable and hence most
important for embedded programming though its very simple to understand. Binary system can be
best understood by using an example to convert Binary to Decimal.
Lets take an example and try to understand binary to decimal conversion :
Consider a binary number say : 10011 which needs to be considered into decimal. Each bit in the binary
number carries a speci䎸껠c multiplication factor or say ‘weight’ or say ‘order’. By default the bit on
extreme right is starting or the 0th bit and that on the extreme left is last bit. Hence the 1st bit
(technically – 0th since in computing counting starts from 0 and not 1 hence as called ‘0 indexed’
system) from the right will have an order of 20 , next bit will have an order of 21 and so on.
Starting form the LSB i.e Least signi䎸껠cant bit from RIGHT we multiply each bit with increasing
power of 2 i.e. Bit 0(LSB) will be multiplied with 20 , Bit 1 multiplied with 21 , Bit 2 multiplied with 22
and on.
After this we simply add all products to get the converted number which is in Decimal.


FACEBOOK

OCFreaks.com
1.7K likes

Like Page

Be the first of your friends to like this

Now we replace each group by its Hex representation. in binary system too 011 . 0011 . 21 and 20 or simply 8-4-2-1. A group of 4 bits is called a Nibble and that of 8 bits is called a Byte. These are 23 . Now the group on the extreme left has only 2 bits so we can append zeros to keep things straight forward. Binary => 0010 1010 0100 1110 Hexadecimal => 2 Hence Hexadecimal_of(1010101001110) = 2A4E A 4 E .In our case we have 5 digits hence our last power of 2 will be 24 with 20 begin the 䎸껠rst : Order / Multiplication Factor(MF) 24 23 22 21 20 Bit Value at each Position 1 0 0 1 1 Value times the Order/MF 24 23 22 21 x1 =2 20 x1 =1 Sum 16+0+0+2+1 =19 x1 =16 x0 =0 x0 =0 Now we simply add the above products to get Decimal of 01011. Hence ‘4’ is a very important number in this case. Decimal_of(01011) = 16+0+0+2+1 = 19 Note : As with decimal . 00011 mean ’11’ since the leading zeros have no meaning and can be discarded.e from right. since 09 or 009 or 0009 mean ‘9’(the leading zeros have no signi䎸껠cance) . Consider a binary number : 1010101001110 . Note that the grouping into 4 starts from right side. Hence . Also the binary representation of any hexadecimal ‘symbol’ or ‘digit’ has only 4 ‘orders’ or ‘weights’ or ‘multiplication factor’ associated. Hexadecimal and Binary: Decimal Hexadecimal Binary 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111 8 8 1000 9 9 1001 10 A 1010 11 B 1011 12 C 1100 13 D 1101 14 E 1110 15 F 1111 From simple observation we can deduce the fact that : to convert any binary number to hexadecimal we need to 䎸껠rst group the bits where each group contains 4 bits and then directly replace that group with its equivalent hexadecimal from the above table. we can group it as 10-1010-0100-1110. Lets have a look at the conversion chart below for Decimal. So in hexadecimal basically we deal with Nibbles. 22 . Hence we get : 0010-1010-0100-1110 . First . Similar to above is conversion from Binary to Hexadecimal as follows: Recall that each Hexadecimal Digit is represented by ‘exact’ 4 bits. We start the grouping from LSB i.

Converting Hexadecimal to Binary: This is as simple as counting 1. of each Hex Digit 1011 0011 1001 1111 0001 1010 Hence Binary_of(B39F1A) = 101100111001111100011010 Note that each digit is replaced with exact 4 bits .. Thats it! For eg.e 3 is replaced by 0011 and not ’11’. △   ▽ • Reply • Share › Umang Gajera > Vasant Prabhu • 3 years ago Thanks for notifying about the typo! :) Update the table with correct values.. i. Share this:  Share Tags: embedded  Like programming  Tweet tutorial  Share  Share  Share  Previous GSKILL RipjawsX 4GB DDR3 1600Mhz CL9 Review Next  Tutorial : Embedded programming basics in C – bitwise operations ABOUT THE AUTHOR Umang Gajera  3 Comments   Recommend    1  OCFreaks! ⤤ Share  Login Sort by Newest Join the discussion… Stuaan • 2 years ago Thank man Great tutorial It will definitely help for beginner who doesn't know about the number system this is only basics but I think it is important for newer one △   ▽ • Reply • Share › Vasant Prabhu • 3 years ago binary to decimal conversion ­­­ theres a typo error . △   ▽ • Reply • Share › ✉ Subscribe d Add Disqus to your site Add Disqus Add ὑ Privacy . Also this method is NOT applicable for conversion from Decimal to binary.3 :P.2. Simply replace each Hexadecimal digit with its binary equivalent. consider a Hex number say B39F1A Replacing Each Hex digit with its binary equivalent we get : Hexadecimal Digit B 3 9 F 1 A Binary equi. the table needs a correction ­­ Bit Value at each Position ­­ 2^3 should be 0 and for 2^4 should be 1 . Replacing it with ’11’ will change the value of the number.

(c) OCFreaks! 2014. Community Server Monitoring with Livewatch.de Register Contact Us .