How do you represent the (decimal) integer 50 in, oh, “hexadecimal,” otherwise known as base-16? Recall that decimal is simply base-10, and binary is simply base-2. Infer from those base systems how to represent this one!
0x32
To convert any number to any base (let's take 16 as base and 500 as the number we're converting. You figure it out for 50), you first need to figure out the largest power that is still smaller than your number. For example: 1 (16^0) fits in 500, 16 (16^1) fits in 500, so does 256 (16^2) , but 4,096 (16^3) does not. So start with 256 (16^2): how many times does that fit in 500? Once. So our first digit is a 1. Than take the remainder (500 - 1 * 256 = 244). How many times does 16 (16^1) fit into that number? Fifteen times, so our next digit is e (a = 10, b = 11, etc.). Again, we take the remainder (244 - 15 * 16 = 4). How many times does 1 (16^0) fit into that? Four times. That makes our last digit a 4. Therefore, 500 is hexadecimal is 0x1e4 (the 0x indicating it's base 16). What this says is that 500 = 1 * 16^2 + 15 * 16^1 + 4 * 16^0. Now try this with 50.
Join our real-time social learning platform and learn together with your friends!