![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2005
Posts: 1
Rep Power: 0
![]() |
How to convert from any base number system to any base in TrueBasic?
How to convert from any base number system to any base in TrueBasic?
and if you don't know, do you know how to just convert any base to hexidecimal? |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4
![]() |
It's not so easy... That would be a little complicated algorithm...
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
you need to write individual algorithms for each case. if you're working with numbers of unknown size, the problem grows exponentially in difficulty. and you can fix that with using that very mathematical operation in your algorithm...
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
I dont know about truebasic, but I dont think the algorithm would be that hard.
I'd first take the number and convert to base10 then convert that to hex To convert any base you need to know how big the base is, and if the base goes over 10 be able to convert the letters it uses to the number. If you get ff, conver that to 16 and 16. (What do bases do after you run out of letters?) Anyways, pase the number like a string, starting with the first character Example, base 11 b3a a = 10 . position = 0. number x base^position 10x11^0 = 10 3 = 3 . position = 1 3x11^1 = 33 b = 11 position = 2 11x11^2 = blah base10 = blah+33+10 convert to hex I could be wrong, but this does not seem hard to implement as long as you know what base it is.
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi freelance scripts - http://ryanguthrie.com/index.html |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
I had to take a class on true basic, i think i remember how to write it...
[php] Input "What is the number? ";num Let hexChars$ = "0123456789ABCDEF" Let hexStr$ = " " Let i = 0 While num > 0 i = i + 1 hexStr$ = hex$[(int(num/16)/int(16^i)) int(num/16)/int(16^i)+1] & hexStr$;num = num / 16(int(num/16)) Wend hexStr$ = trim$(hexStr$) print hexStr$ [/php]
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|