Вы находитесь на странице: 1из 4

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 suciently 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
signicant digit. In out case its 4. While the digit on extreme LEFT is called MSD or Most Signicant Digit
i.e 2 It most signicant 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 specic 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 signicant 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.7Klikes

LikePage

Bethefirstofyourfriendstolikethis

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

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 , Decimal_of(01011) = 16+0+0+2+1 = 19
Note : As with decimal , since 09 or 009 or 0009 mean 9(the leading zeros have no signicance) ,
in binary system too 011 , 0011 , 00011 mean 11 since the leading zeros have no meaning and
can be discarded.
Similar to above is conversion from Binary to Hexadecimal as follows:
Recall that each Hexadecimal Digit is represented by exact 4 bits. Hence 4 is a very important
number in this case. A group of 4 bits is called a Nibble and that of 8 bits is called a Byte. So in
hexadecimal basically we deal with Nibbles.

First , Lets have a look at the conversion chart below for Decimal, Hexadecimal and Binary:
Decimal Hexadecimal Binary
0

0000

0001

0010

0011

0100

0101

0110

0111

1000

1001

10

1010

11

1011

12

1100

13

1101

14

1110

15

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 start the grouping
from LSB i.e from right.
Also the binary representation of any hexadecimal symbol or digit has only 4 orders or weights
or multiplication factor associated. These are 23 , 22 , 21 and 20 or simply 8-4-2-1.

Consider a binary number : 1010101001110 , we can group it as 10-1010-0100-1110. Note that the
grouping into 4 starts from right side. Now the group on the extreme left has only 2 bits so we can
append zeros to keep things straight forward.
Hence we get : 0010-1010-0100-1110 , Now we replace each group by its Hex representation.
Binary =>

0010 1010 0100 1110

Hexadecimal => 2
Hence Hexadecimal_of(1010101001110) = 2A4E

Converting Hexadecimal to Binary: This is as simple as counting 1,2,3 :P. Simply replace each
Hexadecimal digit with its binary equivalent.. Thats it!
For eg. consider a Hex number say B39F1A
Replacing Each Hex digit with its binary equivalent we get :
Hexadecimal Digit

Binary equi. 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 .. i.e 3 is replaced by 0011 and not 11.
Replacing it with 11 will change the value of the number. Also this method is NOT applicable for
conversion from Decimal to binary.

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

3Comments
Recommend

OCFreaks!

Share

Login

SortbyNewest

Jointhediscussion
Stuaan2yearsago

ThankmanGreattutorialItwilldefinitelyhelpforbeginnerwhodoesn'tknowaboutthenumber
systemthisisonlybasicsbutIthinkitisimportantfornewerone

Reply Share
VasantPrabhu3yearsago

binarytodecimalconversiontheresatypoerror,thetableneedsacorrectionBitValueateach
Position2^3shouldbe0andfor2^4shouldbe1.

Reply Share
UmangGajera>VasantPrabhu3yearsago

Thanksfornotifyingaboutthetypo!:)Updatethetablewithcorrectvalues.

Reply Share
Subscribe d AddDisqustoyoursiteAddDisqusAdd

Privacy

(c) OCFreaks! 2014.

Community

Server Monitoring with Livewatch.de

Register

Contact Us

Вам также может понравиться