r/AskComputerScience • • May 04 '26
Need help understanding why hexadecimal is sometimes portrayed by "power of 0" in rasterized explanations.
Hello, sorry if this is a really basic question for this sub, but i couldn't find a "newbie question"-esque thread.
I am in the process of learning the basics of computing and while i understand the workings of it, hexadecimal numbers keep getting explained to me in this rasterized form, in which they add i this case (1 X 16)+(8 X 1), but it reads to me like the 16^0 would make for
(8 X (16 X 0)) when it instead seems to only multiply it if the power is "> 0"
| 1 | 8 |
|---|---|
| 16 | 1 |
| 161 | 160 |
Can someone explain this, as i have a hard time googling it since i cannot put it into words myself. Thank you.
Edit: Thanks for the answers, it seems i have been improperly thought and misled how and what powers are in my school days.
18
u/dkopgerpgdolfg May 04 '26 edited May 04 '26
It's the same with decimal numbers, maybe that helps to understand better.
Consider 4567 (four thousand five hundred sixty seven)
It can be written as 4000 + 500 + 60 + 7
which is 4x1000 + 5x100 + 6x10 + 7x1
which is 4x103 + 5x102 + 6x101 + 7x100
What you do is the same with 16 instead of 10.
The hex number AB33, while knowing that A means 10 and B means 11, is:
10x163 + 11x162 + 3x161 + 3x160
8x160 is not the same as 8x16x0. And 160 (and 100) are 1
7
u/not-just-yeti May 04 '26 edited May 06 '26
As others have pointed out, your misunderstanding stems from "raising to the 0 power". So maybe all the explanations here are simply begging the question "why the *&^! is 16^0 = 1?" It does at first sound weird to say "16 multiplied by itself no times at all is 1".
I'll give several independent reasonings:
counting (#1, probability): If you flip a coin 3 times, your chance of getting 3 heads is (½)^3 And if you flip it twice, the chance of getting 2 heads is (½)^2 and with one flip your chance of getting 1 head is (½)^1 . SO: if you flip 0 coins, what is the probability that 0 of them will be heads? 1, suggesting (½)^0 = 1 indeed.
the pattern/code: Write a loop to compute 6^n :
If you initialize
soFarto 0 because that's its value "not having multiplied anything yet", then we'd return 0 for every input. Could you write code to make the input n=0 a special case handled differently than anything else, to support the (misplaced) hope that 6^0 = 0 but 6^2 = 36? Yes you could, but the fact that you need a special case suggests that you haven't chosen the cleanest definition.More generally, it's not even just "raising to the 0"; it's "what is the product of no numbers at all?":
(If you think your birthday-suit isn't an outfit, change the problem to ordering a fancy prix fixe meal where there's only one main course, but you get to choose one of 3 salads, one of 5 desserts, and one of 8 sauces; 3*5*8 possible meal options. But if only the salads are choosable, then just 3 possible options. And if no choices at all, then there's still 1 meal option, not 0.)
This counting argument also illustrates why 0! = 1. And, you can also think of the cleanest-code argument already mentioned: if you write
productOfAllNumbersInSet(s); you'll again initializesoFar = 1, so the simple-code suggests 1 is a good answer for the product of the numbers in empty set{}.sumSoFar=0. Similarly, since 1 is the identity element for multiplication (n*1=n, for all n), the product of no numbers is 1, and we'd also useprodSoFar=1in a loop-that-computes-product.This last one actually generalizes to non-numeric things: If you are "
and"ing boolean conditions, each time you add a condition it's only harder to end up withtrue. Phrasing the another way 'round: every time you remove aand'd condition it is easier to end up withtrue. So what if you take theandof no conditions at all? That's the easiest way to end up withtrue, and sure enoughtrueis the identity element forand(n && true=n, for any boolean valuen), and your code would initializeandSoFar = truebefore the loop.Finally, if you want to cause arguments with a math major: Should 0^0 be 1, 0, or undefined? (Hint: it's actually best defined as 1! But that takes more justification, esp. when compared to why 0/0 is properly considered undefined.)
2
u/epotocnak May 04 '26
So, I'm going to be that person, and ask where you were when they taught bases in school. I learned them in 5th grade, including exponential notation. When I took Intro to Computer Systems a long time ago, we spent 30 minutes on hex code because my professor assumed we all understood what base 16 (and all bases) were, and continued on.
2
u/g---e May 04 '26
It's base16, and we start at index 0. Anything to the power of 0 equals to 1
1
u/Educational-Paper-75 May 04 '26 edited May 04 '26
18 in hexadecimal equals 1 * 16 + 8 * 1=24 in decimal. Every hex digit is to be multiplier by 16 to the power of the position counting right to left starting at position zero just like we do in decimal notation. (Note that 160 equals 1.)Of course you need 16 digits not 10 that's why they use letters a through f to represent hexadecimal digits 10 through 15.
1
u/MasterGeekMX BSCS May 04 '26
It all boils donw to the fact that any number, no matter the base, rasied to the power of zero, is one.
1
u/AYamHah May 04 '26
Top comment has got it, but if you're struggling make your example simpler.
0x51 = 5 * 16 ^1 + 1 * 16 ^0
Remember that anything to the power of 0 is 1.
So
0x51 = 80 + 1
0x51 = 81
1
u/[deleted] May 04 '26
[removed] — view removed comment