Author Topic: Number systems  (Read 11664 times)

0 Members and 1 Guest are viewing this topic.

Offline Anima

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 133
  • Rating: +4/-0
    • View Profile
Number systems
« on: August 01, 2011, 01:32:48 pm »
I currently work at a small TI-BASIC program that converts numbers in the following several other systems:
Binary -> Decimal
Decimal -> Binary
Hexadecimal -> decimal
Decimal -> Hexadecimal

Currently I am working to convert a binary number to decimal. How to do it mathematically, I know, but I like the whole then fails to implement in TI-BASIC. Therefore I need some help from a math expert, can someone give me a little food for thought / Code snippets / or similar. to give to whom I do that? Would be very nice.

(I used Google translator, original german thread)


Sorry for my bad English. I'm German.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Number systems
« Reply #1 on: August 01, 2011, 01:39:52 pm »
Spoiler For The Most optimized base converter possible:
Code: [Select]
PROGRAM:BASECONV
:Input Str1
:Ans→A
:Ans(2→A
:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ→Str2
:length(Str1
:sum(seq(LA(1)^(Ans-A)(inString(Str2,sub(Str1,A,1))-1),A,1,Ans→B
:"░ // one space
:For(C,1,log(AB+1)/log(A
:sub(Str2,int(E5×√2+AfPart(B/A^C)),1)+Ans
:End
:Ans

Example of usage:

Code: [Select]
{16,10:prgmBASECONV
?7C
► 124


In other words:
Code: [Select]
{<Base in>,<Base to be converted to>:prgmBASECONV
Input Number
► Answer

Code courtesy of weregoose.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Anima

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 133
  • Rating: +4/-0
    • View Profile
Re: Number systems
« Reply #2 on: August 01, 2011, 01:50:03 pm »
There is an error in line 9:
ERR:ARGUMENT

I used your example code.


Sorry for my bad English. I'm German.

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Number systems
« Reply #3 on: August 13, 2011, 07:15:09 pm »
BIn to dec? HUm...
I  sugger you to make a system who'll decompose your decimal into a list or a variable right to left, then if the Nst number, then total += 2^N
00110100010 //left to right

I don't know how to explain, but i already made this...
Let me think...
int(10(float(.1num)) gives you the last number
then
(int(100(float.01(num))-last)/0 gives you the before-last number, and so on...

Hint: int log gives you the numbers composing your number -1.
int log 1000011 = 6

If you use the strings, that would be easily: you just read the string right to left, then apply the famous Total + 2^n->Total!
Excuse-me, I don't program with Ti...

a Hexadeciaml number support 4 bits (2^4 = 16), So divideyour numbers into 4 bits, then convert to Hexa.

Hexa to dec is easy, I think that don't need any help. Yes? So:
Looping right form left, then convert 16^N, i think.
« Last Edit: August 13, 2011, 07:19:55 pm by Eiyeron »

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Re: Number systems
« Reply #4 on: August 13, 2011, 07:49:58 pm »
Nowhere near as optimized as weregoose's, but I made a program for all of the original systems you stated found here. I'm sure the loops could be combined to do something like weregose's, but I' too lazy to do something like that on-calc at the moment.

EDIT: Fixed my incorrectedness :P
« Last Edit: August 13, 2011, 07:54:35 pm by BlakPilar »

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Number systems
« Reply #5 on: August 13, 2011, 07:52:16 pm »
Weregoose wrote that code I posted, not me :P

Sorry if that wasn't clear.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Re: Number systems
« Reply #6 on: August 13, 2011, 07:56:54 pm »
Weregoose wrote that code I posted, not me :P

Sorry if that wasn't clear.

That darn weregoose... Always being referenced to with his mega-optimized code and whatnot...
« Last Edit: August 13, 2011, 07:57:13 pm by BlakPilar »