Professional Documents
Culture Documents
Handout+2+ +What+Are+Hexadecimal+Numbers+ +MMB+ +v007
Handout+2+ +What+Are+Hexadecimal+Numbers+ +MMB+ +v007
Handout+2+ +What+Are+Hexadecimal+Numbers+ +MMB+ +v007
1. Writing all those 0’s and 1’s can take a lot of time and space. Remember what the value of count
looked like?
2. To make our lives easier, developers often use another number base besides decimal and binary –
base 16 or hexadecimal (often simply called “hex”).
3. Because both binary and hexadecimal are based on powers of 2, it is relatively easy to convert
between the two.
Begin by writing down your number from right to left while grouping the binary number into
groups of 4 digits. (Note, we have color coded the binary number to better illustrate this
procedure.)
1101 0111
5. Believe it or not, we are almost done. Now, look-up each group of four binary digits on the table
above in step 2.
5 D 7
6. There are a couple of different way that you can indicate that a number is in hexadecimal:
Each of these are equally valid ways of denoting a hexadecimal number. However, in this course,
and in most programming languages, we will be using the second option.
As before, if we do not use any suffix, we (and CCS) will always interpret a number to be
decimal.
7. It is just as easy to convert from hexadecimal to binary. Let’s convert 0xE57A into binary.
Begin by writing down the hexadecimal number with its digits spaced out a little bit.
E 5 7 A
E 5 7 A
9. Ok, we are almost done. Remember, each hexadecimal digit will have a four digit binary
equivalent. Here is the original table from step 2, but this time, we have added another column
that has the leading 0’s inserted in the binary column.
10. Now, look-up each group of hexadecimal digits on the table above in step 2 and write down their
binary equivalent:
E 5 7 A
to be equivalent.
12. The following program will let you see how CCS uses and represents hexadecimal numbers.
Create a new project called Hexadecimal in CCS and paste the program into main.c
(Instructions for creating projects can be found in the Section 1 handout, Let’s Get Started.
The program is identical to the one in the binary handout, but this time, the program can count to
the hexadecimal number 0xFFFF.
main()
{
WDTCTL = DEVELOPMENT; // Disable watchdog timer for development
13. Save and Build your new program. Once the project is done building, go ahead and launch the
CCS Debugger.
15. Now, you can keep clicking Step Into and watch CCS count up in hexadecimal.
16. Pay special attention as the value of count increments from 0x00000009 to 0x0000000A.
18. When you are ready, click the Terminate button to close the CCS Debugger and return to the
Editor.
In no event shall the owner or contributors to the tutorials and software be liable
for any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services; loss of
use, data, or profits; or business interruption) however caused and on any theory
of liability, whether in contract, strict liability, or tort (including negligence or
otherwise) arising in any way out of the use of this software, even if advised of
the possibility of such damage.