Converting Hex and Decimal
How big are FEED, DEAF, DEAD, BEAD, and ABE?

Decimal Numbers When you think of decimal numbers, you might think of numbers like 12.4382 or 0.625. That's not really what I mean here. I'm not talking about numbers written with a decimal point or decimal mark[1]. By decimal numbers, I mean numbers that are written in Base 10. In everyday life, you and I use base 10, known as the "decimal numbering system". Since decimal refers to the number 10, and we humans have ten fingers and ten toes, we tend to like using numbers in groups of 10. Tens are built into our numbering system. For example, let's take the numbers 234, 16, and 9001. We can split each of these numbers into multiples of powers of 10: 234 = 2*100 + 3*10 + 4*1 16 = 1*10 + 6*1 9001 = 9*1000 + 0*100 + 0*10 + 1*1 Here I have used the * symbol to mean multiplication. If you prefer exponents, also known as powers, here you go: 234 = 2*102 + 3*101 + 4*100 16 = 1*101 + 6*100 9001 = 9*103 + 0*102 + 0*101 + 1*100 If you're no math whiz, you're probably going, "Oh no, we're already doing math?" Don't worry, assembly doesn't require high level math skills. You don't even have to worry about fractions (mainly because the normal registers can't use anything but integers... whoops did I reveal too much?) Hexadecimal Unfortunately, computers don't have 10 fingers and 10 toes. In fact, they don't have any at all! The people who make these machines decided that it's way too complicated to make a computer that can count exactly like a human. So, computers use binary instead, which we can write in a shortened form - hexadecimal. Hexadecimal, often called hex for short, is the method of grouping numbers into powers of 16 instead of powers of 10. We may call hexadecimal Base 16. The biggest digit in decimal is 9. If I want to represent a number higher than 9, I need more than one digit. For example, to represent nineteen, I need to put the number one and the number nine next to each other: 19. So, decimal numbers only use the digits 0 through 9, a total of ten different digits. But hexadecimal numbers need more than ten digits. They need to fit 16 types of numbers into a single digit. Now, obviously, the higher numbers like 10, 11, 12, 13, 14, and 15 don't fit into one digit. To solve this issue, hexadecimal numbers have some alphabetical letters used as numerical digits. A represents 10, B represents 11, C represents 12 ... all the way up to 15, which is represented by F. Letters G and beyond aren't used in hexadecimal. To count in hexadecimal, you do this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B, 1C, 1D, 1E, 1F, 20, ... Notice that "A" in hexadecimal is actually 10 in decimal. 10 in hex means 16 in decimal. 1F in hex is 31 in decimal, and 20 in hex is 32 in decimal, and so on. Here are some hex numbers with their decimal equivalents:
    Hex numbers: 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F,10,11,12,13,14,15,16,17,18,19
    In decimal:  0,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

    Hex numbers: 1A,1B,1C,1D,1E,1F,20,21,22,23,24,25,26,27,28,29,2A,2B,2C,2D,2E,2F,30
    In decimal:  26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48

    Hex numbers: 31,32,33,34,35,36,37,38,39,3A,3B,3C,3D,3E,3F,40,41,42,43,44,45,46,47, ...
    In decimal:  49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71, ...
Now let's look at the numbers 23D, AF, and 2329 in hex. Hexadecimal numbers: (notice we're using powers of 16, not 10.) 23D (hex) = 2*162 + 3*161 + 13*160 = 573 (dec) AF (hex) = 10*161 + 15*160 = 175 (dec) 2329 (hex) = 2*163 + 3*162 + 2*161 + 9*160 = 9001 (dec) Windows Calculator Of course, you don't have to convert hexadecimal to decimal by hand. To convert, just use the Windows Calculator. Here I have pictures of the Windows XP and Windows 7 Calculators. The biggest decimal number you can convert is 9,223,372,036,854,775,807 and the smallest is -9,223,372,036,854,775,808. Hexadecimal Notations In other guides, text files, and programs, you'll typically find a few types of notations that distinguish hex numbers from decimal numbers. 0x312 $312 312h To make sure that someone else knows that you're talking about hex numbers and not decimal numbers, you can use the above three notations. You can prefix the hexadecimal number (in this case, hexadecimal 312), with "0x" or a dollar sign "$". Alternatively, appending the letter "h" to the end of the number will also work. I'd like you to pay special attention to the prefix 0x. 0x600 just means "600, the hex number". This notation is one of the most common forms. I know that 0x600 looks like "0 times 600" but that's not what it means. Remember... 0x means hex number! This ASM guide won't actually be using the three notations mentioned above. All numbers are assumed to be hex numbers unless otherwise stated. In places where things could get confusing, I'll put (dec) after decimal numbers and (hex) after hexadecimal numbers, such as here: 30 (hex) = 48 (dec) Just remember that if you see 0x, $, or the h notations in any other guides, those numbers are almost certainly hexadecimal numbers. Navigation Previous Lesson: Hexadecimal Next Lesson: Firecracker Table of Contents [1]In computer programming, numbers that have a decimal point, such as 9.18607, are called floating point numbers. There are ways to use floating point numbers in assembly, but we won't learn about them until much later.