Advertisement

Counting Unit Conversion

Started by April 19, 2002 04:24 PM
14 comments, last by black_mage_s 22 years, 9 months ago
quote:
Does anyone here know how to convert from a base 10 counting system to a base 8? And vice versa?
Yeah :
quote:
decimal to octal :

1457 = 182 * 8 + 1
182 = 22 * 8 + 6
22 = 2 * 8 + 6
2 = 0 * 8 + 2

Thus 1457d = 2661o

octal to decimal :

2661o = 2*8^3 + 6*8^2 + 6*8^1 + 1*8^0 = 1457d
quote:
Just so i can do it by hand.
Isn't it a "by hand" example?

[edited by - Bloodscourge on April 21, 2002 7:32:20 AM]
I know that I don't know nothing... Operation Ivy
Another example :

decimal to octal :

31057 = 3882 * 8 + 1
3882 = 485 * 8 + 2
485 = 60 * 8 + 5
60 = 7 * 8 + 4
7 = 0 * 8 + 7

Then 31057d = 74521o

octal to decimal :

74521o = 7*8^4 + 4*8^3 + 5*8^2 + 2*8^1 + 1*8^0 = 31057d

Got it?

[edited by - Bloodscourge on April 21, 2002 7:47:55 AM]
I know that I don't know nothing... Operation Ivy
Advertisement
Another way to see the decimal to octal conversion :
31057 |  8------+------   1  | 3882 |  8      |------+------      |   2  | 485  |  8             |------+------             |  5   |  60  |  8                            |------+------                                    |  4   |  7   |  8                           |------+------ <---- this part not necessary                           |  7   |  0                                    | 
It' clear that it's a chain of division by 8. Read in reversed order the remainders and you have your base 8 number -> 74521o

[edited by - Bloodscourge on April 21, 2002 8:23:36 AM]
I know that I don't know nothing... Operation Ivy
If you don''t need your program to do it, then why not just use a calculator that can do the conversion (such as the one that comes with Windows (if that''s the OS you''re using)).
A modulus divide is just taking the remainder on a division. So 17/8 is 2+1/8 and the remainder on the division is 1.
Keys to success: Ability, ambition and opportunity.
I really like the idea of a society which speaks in octal!

If you''re using C...

printf("%o in base 8 is %d in base ten",n,n);

You can also use scanf to input an octal number. This seems easier than the other methods.

This topic is closed to new replies.

Advertisement