Post Reply 
How to change bases?
04-10-2019, 12:46 AM (This post was last modified: 04-10-2019 12:47 AM by toml_12953.)
Post: #11
RE: How to change bases?
(04-08-2019 12:44 AM)Don Shepherd Wrote:  
(04-07-2019 02:45 PM)kevin3g Wrote:  Say I have a number in base 3 and want to convert it to base 6 or any base conversion. How would I do this?
There may be a better way, but whenever I have written a base conversion program to convert from one base to another, if neither base is 10, I first convert the number to base 10, then to the other base.

To convert base 3 number to base 10, multiply digits by corresponding powers of 3 and add. To convert base 10 number to base 6, for example, divide the base 10 number by 6 and save the remainder, then divide the quotient by 6 and save the remainder, and repeat until quotient is 0. When you "save the remainders," first one is the rightmost digit of your answer.

To convert 45 base 8 to base 16 you could nest converts like this:

convert(convert([5 4],base,8),base,16)

which would put out [5 2] since 25 is the hex equivalent of 45 octal. I know the Prime has these bases built-in but the power of this method is that you can use any bases, not just 8 and 16.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
How to change bases? - kevin3g - 04-07-2019, 02:45 PM
RE: How to change bases? - rprosperi - 04-07-2019, 03:31 PM
RE: How to change bases? - Aries - 04-07-2019, 03:50 PM
RE: How to change bases? - Don Shepherd - 04-08-2019, 12:44 AM
RE: How to change bases? - toml_12953 - 04-10-2019 12:46 AM
RE: How to change bases? - Albert Chan - 04-27-2019, 06:52 PM
RE: How to change bases? - Joe Horn - 04-08-2019, 01:14 AM
RE: How to change bases? - rprosperi - 04-08-2019, 01:36 AM
RE: How to change bases? - Joe Horn - 04-08-2019, 02:12 AM
RE: How to change bases? - John Keith - 04-08-2019, 01:11 PM
RE: How to change bases? - rprosperi - 04-08-2019, 07:39 PM
RE: How to change bases? - parisse - 04-08-2019, 09:29 AM
RE: How to change bases? - Joe Horn - 11-29-2019, 06:34 PM
RE: How to change bases? - toml_12953 - 11-30-2019, 04:48 AM
RE: How to change bases? - Joe Horn - 11-30-2019, 01:01 PM
RE: How to change bases? - rprosperi - 11-30-2019, 02:41 PM
RE: How to change bases? - toml_12953 - 11-30-2019, 03:16 PM
RE: How to change bases? - Steve Simpkin - 11-30-2019, 06:26 PM
RE: How to change bases? - Joe Horn - 11-30-2019, 07:21 PM
RE: How to change bases? - toml_12953 - 11-30-2019, 08:34 PM
RE: How to change bases? - Didier Lachieze - 12-01-2019, 08:43 AM
RE: How to change bases? - rprosperi - 12-01-2019, 02:42 PM
RE: How to change bases? - Tim Wessman - 12-02-2019, 06:16 AM
RE: How to change bases? - YEDERF - 12-03-2019, 02:05 AM



User(s) browsing this thread: 1 Guest(s)