开发者

How can I convert a number from base 8 to base 10?

I know 75(base8)开发者_StackOverflow = 61(base10), but I can't easily find the formula for this. How does one convert from base 8 to base 10?


To convert any base to base 10 just do the following:

For every digit in the different base multiply that by the base and digit. For example:

75 (base 8) = 7*8^1 + 5*8^0 = 61 

Works for any base ... binary, hex, you name it just do that and it will convert to base 10.


0 * 85 + 0 * 84 + 0 * 83 + 0 * 82 + 7 * 81 + 5 * 80 = 61


The formula is 18 = 110 and 108 = 810. Everything else can be derived from that.

If you have a sequence of base 8 digits you want to convert to a base 10 number, process them from left to right, keeping a total you initialize at zero. For each digit x, set the total to 8*total+x. After processing the last digit, the total will be the base ten value of the base 8 sequence.


75 in base 8 = 5*8^0 + 7*8^1 = 5 + 56 = 61

In general, to convert the number a_1a_2a_3...a_n from base k to base 10, use the formula:

a_n*k^0 + a_(n-1)*k^1 + ... + a_1*k^(n-1).


given this is a programming site:

int oct_to_dec = 075;
printf("%d",oct_to_dec);


137461(base8) = 1 x 8^0 + 6 x 8^1 + 4 x 8^2 + 7 x 8^3 + 3 x 8^4 + 1 x 8^5


For Integers, from base 8 to base 10, say, you have 144 in base 8, then to convert it to base 10,

multiply the right most/least-significant digit by 8 raised to 0 that is 1 So, 1 x 4 = 4 now move towards left and multiply the digit on immediate left by 8 raised to 1(8), So, 8 x 4 = 32 again, move towards left and multiply the digit on immediate left by 8 raised to 2(64), So, 64 x 1 = 64

Now, add all these = 64 + 32 + 4 = 100.

So 144 in base 8 is 100 in base 10.

Had there been more digits towards the left, we would have followed the same pattern and later add them to get our answer. Hope it helped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜