Just to amplify a little on Util's response: A number is just a number and decimal, hex, octal, etc., are just different ways to represent it. To the computer it's just a bunch of bits.
So, why have different representations? Some operations are easier to visualize and check in a different base. For example, I've done a boatload of assembly programming, so I would use hex frequently. One example: If you want to represent the ASCII code for the numbers 0..9 you could use decimal (48=='0', 49=='1', ... 57=='9'), octal (60=='0', 61=='1', ... 71=='9'), hex (30=='0', 31=='1', ... 39='9'), or any other base. But I would use hex because it's easy to remember "just add the digit I want to 30 to get the ASCII code for the digit".
Another example: The same rule generally applies to the alphabet (0x41=='A', 0x42=='B', ...) which makes it fairly easy to convert from a letter to an ASCII code in decimal. And converting from UPPER CASE to lower case is easy, just OR the letter with 0x20 (0x61=='a', 0x62=='b', ...)
If you're programming peripheral chips, such as UARTs or such, you'll find that many of them map specific functions to particular bits in a specific memory or I/O location. For example, the fictional 3141 DWIM chip performs various duties based on the value you write to 0x2718:
So if you write 57 decimal to that location, it's hard to tell what will happen just by looking at the number. Is your precious Z-80 computer safe? Will you take over the world? Will you change your socks? (Hey, it's not Tuesday!)bit 7: Take over the world bit 6: Turn on your porch light bit 5: Change your socks bit 4: Format your hard disk bit 3: Sell Z-80 computer on Ebay "No Reserve L@@K! RARE!" bit 2: Apply lipstick to pig bit 1: Make horse drink bit 0: Lead horse to water
But if you use binary, it's much simpler to tell. Let's see 57 converts to 0011 1001. Drat! Not only do I not get to control the world, but I've left my porch light off! Oh, no! My precious Z-80! Hmmmm.... I've lead the horse to water, but I forgot to make him drink!
</foolish_mode>
In reply to Silly Example (was Re: Hex Numbers and Range Operator)
by roboticus
in thread Hex Numbers and Range Operator
by awohld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |