Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 28th, 2005, 11:00 PM   #1
linzi53
Newbie
 
Join Date: Oct 2005
Posts: 1
Rep Power: 0 linzi53 is on a distinguished road
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?
linzi53 is offline   Reply With Quote
Old Oct 29th, 2005, 3:25 AM   #2
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4 ivan is on a distinguished road
It's not so easy... That would be a little complicated algorithm...
ivan is offline   Reply With Quote
Old Oct 30th, 2005, 1:24 AM   #3
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
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.
bl00dninja is offline   Reply With Quote
Old Oct 30th, 2005, 1:41 AM   #4
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 224
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
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
Mocker is offline   Reply With Quote
Old Oct 30th, 2005, 8:45 AM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
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]
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:01 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC