可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Opening the calculator to do such tiny stuff appears annoying to me ,and I strongly believe in ths saying "the more you know,the better!" so here I am asking you how to convert hexadecimal to decimal.
Till that moment I use the following formula:
Hex: Decimal:
12 12+6
22 22+2*6
34 34+3*6
49 49+4*6
99 99+9*6
I get confused when I move on at higher numbers like C0 or FB
What is the formula(brain,not functional) that you're using?
回答1:
If you consider that hexadecimal is base 16, its actually quite easy:
Start from the least significant digit and work towards the most significant (right to left) and multiply the digit with increasing powers of 16, then sum the result.
For example:
0x12 = 2 + (1 * 16)
= 18
0x99 = 9 + (9 * 16)
= 153
Then, remember that A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15
So,
0xFB = 11 + (15 * 16)
= 251
回答2:
That's not the formula.. that's not even somewhat like the formula...
The formula is:
X*16^y where X is the number you want to convert and y is the position for the number (from right to left).
So.. if you want to convert DA145 to decimal would be..
(5 * 16^0) + (4 * 16^1) + (1 * 16^2) + (10 * 16^3) + (13 * 16^4)
And you have to remember that the letter are:
A - 10
B - 11
C - 12
D - 13
E - 14
F - 15
回答3:
I pretty much stopped doing this when I found the hex numbers I was working with were 32 bits. Not much fun there.
For smaller numbers, I (eventually) memorized some patterns: 10 = 16, 20 = 32, 40 = 64, 80 = 128 (because 100 = 256, and 80 is one bit less). 200 = 512 I remember because of some machine I used to use whose page size was 512 (no longer remember what machine!). 1000 = 4096 because that's another machine's page size.
also, 64=100, 32=50, B8=200
That's about all. Beyond that, I add.
回答4:
For the record, your brain does use a functional method of finding the answer. Here's the function my brain uses to find the value of a hexadecimal number:
- Divide the hexadecimal number into individual digits.
- Convert each digit to it's decimal value (so 0-9 stay the same, A is 10, B is 11, etc.)
- Starting at the rightmost digit, multiply each value by 16^X power, where X is the distance from the rightmost digit (so the rightmost digit is 16^0, or 1, next is 16^1, or 16, next is 16^2, or 256, etc.)
- Add all the values together.
回答5:
Memorize the decimal values of 20h, 40h, and so on, up to E0h. (I suppose you already know 100h.)
Then get the decimal values if other numbers by adding or subtracting a number from 1 to 16.
回答6:
The decimal value will be
20h = 0x16^0 + 2x16^1 = 0x1 + 2x16 = 0 + 32 = 32
in decimal notation, or (32)10
.
For 40h
in hexa we will have 64
in decimal, for EOH
, we will have 224
in decimal.
回答7:
In determining the decimal value of a specific index in a word, generalized for all bases:
b^i*n
where b is the base, i is the index in the word, and n is the numeric value at the index. Remember this by remembering that b,i,n = bin = short for binary.
Examples:
for base2 (binary) 1000, getting the value where the 1 is located:
b = base, ie base2: b=2
i = 0-based index within word, ie 1000, 1 is in 3th index, i=3
n = number listed in index, ie 1000, 3th index is 1, n=1
so, 2^3*1 = 8
for base10 (decimal) 900, getting the value where the 9 is located:
b=10, i=2, n=9 : 10^2*9 = 100*9 =900
for base16 (hexadecimal) 0x0f0, getting the value where the f is located:
b=16, i=1, n=15 (0-9,a-f,f=15) : 16^1*15 = 16*15 = 240
Note that this can be used to determine the value of each index in a word, then each value can be summed to determine the full word value.
e.g. 1001, from left to right (order doesn't matter in summation):
(2^3*1=8) + (2^2*0=0) + (2^1*0=0) + (2^0*1=1) = 9
回答8:
I didn't find any of these helpful so here's my way:
Turn it into two sets of binary numbers to represent each letter, then take the whole binary representation and convert to decimal
Example:
AB
A / B
= 1010 / 1011 in binary
= 171 (128 + 0 + 32 + 0 + 8 + 0 + 2 + 1) in decimal
回答9:
Here's another method that doesn't involve powers of 16 and can be done with pencil and paper:
Start with the leftmost digit. Multiply it by 16 and add to it the second-from-the-left digit.
Then multiply the result by 16 and add to it the third-from-the-left digit. And so on.
For example, converting 0x20A5
to decimal:
2 * 16 + 0 = 32
32 * 16 + 10 = 522 (remember that A is 10 decimal)
522 * 16 + 5 = 8357
And the result of the conversion is 8,357.