Author |
Message |
|
anduril66 Anduril is the Flame of the West!
Member
Joined: 25 May 2003 Posts: 129
|
Posted: 25 Nov 2003 11:55:56 am Post subject: |
|
|
Let's have one of those contests for the smallest program- a dec to hex convertor.
Here is a small hex to dec convertor.
prgmD
Code: :DelVar CInput Str4
:For(A,1,length(Str4
:C+16^(length(Str4)-A)inString("123456789ABCDEF",sub(Str4,A,1->C
:End
:C
I think its 74K. It doesn't store the input as numbers, so you can't convert statements like 04+0A in it.
I did not make a dec to hex convertor, which I found harder to do. I am looking for a small prog to convert decimal numbers to hexadecimal numbers. It can be in asm.
How about a program that adds hex to hex, and outputs hex, or adds hex to dec, and outputs hex? |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 25 Nov 2003 12:51:30 pm Post subject: |
|
|
Code: :Prompt X
:iPart(abs(X->X
:"0X->Str0
:Repeat not(X
:Str0+sub("0123456789ABCDEF",16fPart(X/16),1->Str0
:iPart(X/16->X
:End
:Str0
Edit: This will "work" but give the hexits in reverse order.
Last edited by Guest on 26 Nov 2003 12:26:53 pm; edited 1 time in total |
|
Back to top |
|
|
Arcane Wizard `semi-hippie`
Super Elite (Last Title)
Joined: 02 Jun 2003 Posts: 8993
|
Posted: 26 Nov 2003 10:49:27 am Post subject: |
|
|
Sweet, I was just looking for a simple routine to convert hex to dec and back, only just learned how to convert it myself yesterday (I intended to learn that somewhere last year).
Quote: I think its 74K. I hope that's 74 Bytes, not 74000 Bytes. :)
Don't see any better (smaller) ways of writing those programs.
Last edited by Guest on 26 Nov 2003 10:49:51 am; edited 1 time in total |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 26 Nov 2003 01:39:09 pm Post subject: |
|
|
'n' is the sequential graphing variable. Apparently it can only have an integer value. This program uses Ans as its input; to use you would do '255:prgmH' to convert 255 to hex.
Code: :abs(Ans ->n
:" -> Str7
:While n
:Str7 + sub("01234567889ABCDEF",16fPart(n/16),1 -> Str7
:int(n/16 -> n
:End
:Str7
Same issue as with Sigma's program - reverse digits. I basically shortened his program because I couldn't write an algorithm that would work better. To switch digits to normal, do
Code: :length(Str7 -> N
:" (there is a single space here)
:For(I,0,N-2
:Ans + sub(Str7,N-I,1
:End
:Ans
at the end of the program.
Last edited by Guest on 26 Nov 2003 01:40:21 pm; edited 1 time in total |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 26 Nov 2003 03:40:50 pm Post subject: |
|
|
Okay, this one works for sure.
Code: :DelVar L6DelVar Y
:Prompt X
:iPart(abs(X->X
:"0X->Str0
:Repeat not(X
:Y+1->Y
:16fPart(X/16->L6(Y
:iPart(X/16->X
:End
:Lbl 1
:Str0+sub("0123456789ABCDEF",L6(Y)+1,1->Str0
:DS<(Y,1
:Goto 1
:Str0
Last edited by Guest on 26 Nov 2003 03:43:11 pm; edited 1 time in total |
|
Back to top |
|
|
anduril66 Anduril is the Flame of the West!
Member
Joined: 25 May 2003 Posts: 129
|
Posted: 26 Nov 2003 05:32:13 pm Post subject: |
|
|
Wow, you guys are good. I can't test it now, but does"Repeat(not(X" do the same thing as "While(X".
This is assembly, but can't you set a flag to octal or hex. Would one be able to work on the homescreen in hex after setting the hex flag? |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 26 Nov 2003 08:07:07 pm Post subject: |
|
|
anduril66 wrote: does"Repeat(not(X" do the same thing as "While(X".
Repeat always runs through the loop at least once. I use it to catch an input of zero.
Quote: This is assembly, but can't you set a flag to octal or hex. Would one be able to work on the homescreen in hex after setting the hex flag?
Only if its the TI-85 or TI-86. |
|
Back to top |
|
|
anduril66 Anduril is the Flame of the West!
Member
Joined: 25 May 2003 Posts: 129
|
Posted: 27 Nov 2003 10:37:32 am Post subject: |
|
|
Oh, I don't think an advanced user would need all that error checking.
What does the 83+ hex flag do then? |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 27 Nov 2003 12:53:17 pm Post subject: |
|
|
anduril66 wrote: What does the 83+ hex flag do then?
if FmtHex = 1 and FmtOct =1, then
FmtBin = 1 displays as x/y
FmtBin = 0 displays as xºy'z"
Last edited by Guest on 27 Nov 2003 12:56:04 pm; edited 1 time in total |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 27 Nov 2003 03:02:56 pm Post subject: |
|
|
sigma wrote: anduril66 wrote: does"Repeat(not(X" do the same thing as "While(X".
Repeat always runs through the loop at least once. I use it to catch an input of zero.
why catch the input at all? If it never goes through, the answer stays " ". |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 27 Nov 2003 05:56:05 pm Post subject: |
|
|
Which is the wrong answer. 0 in hex isn't " ", it's 0. |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 27 Nov 2003 07:26:51 pm Post subject: |
|
|
Yes, you're right. I think anyone who put in zero would know the answer anyway before it came out of the calculator.
I just noticed we all use different strings in our programs. Anduril66 used Str4... Sigma used Str0... I used Str7. |
|
Back to top |
|
|
Adm.Wiggin aka Tianon
Know-It-All
Joined: 02 Jun 2003 Posts: 1874
|
Posted: 27 Nov 2003 11:22:07 pm Post subject: |
|
|
i made a REALLY good convert program in basic once, but that was back when i messed with ASM a TON lol so, i lost the whole thing
i was devastated |
|
Back to top |
|
|
Arcane Wizard `semi-hippie`
Super Elite (Last Title)
Joined: 02 Jun 2003 Posts: 8993
|
Posted: 28 Nov 2003 09:21:16 am Post subject: |
|
|
Sir Robin wrote: I just noticed we all use different strings in our programs. Anduril66 used Str4... Sigma used Str0... I used Str7.
Str0 is the best. |
|
Back to top |
|
|
sgm
Calc Guru
Joined: 04 Sep 2003 Posts: 1265
|
Posted: 28 Nov 2003 02:10:29 pm Post subject: |
|
|
Do I get a prize? |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 28 Nov 2003 03:41:25 pm Post subject: |
|
|
Str7 is the best... [vars] [7] [7]
Your prize:
and a bigger one for myself:
Last edited by Guest on 28 Nov 2003 09:14:22 pm; edited 1 time in total |
|
Back to top |
|
|
Arcane Wizard `semi-hippie`
Super Elite (Last Title)
Joined: 02 Jun 2003 Posts: 8993
|
Posted: 29 Nov 2003 06:10:38 am Post subject: |
|
|
Ok, tone it down a bit. |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 29 Nov 2003 03:58:29 pm Post subject: |
|
|
Arcane Wizard wrote: Ok, tone it down a bit.
????? |
|
Back to top |
|
|
Arcane Wizard `semi-hippie`
Super Elite (Last Title)
Joined: 02 Jun 2003 Posts: 8993
|
Posted: 30 Nov 2003 07:05:03 am Post subject: |
|
|
Useless posts and stuff. |
|
Back to top |
|
|
DarkerLine ceci n'est pas une |
Super Elite (Last Title)
Joined: 04 Nov 2003 Posts: 8328
|
Posted: 30 Nov 2003 01:57:38 pm Post subject: |
|
|
Hex -> Dec
Code: seq(1+inString("0123456789ABCDEF",sub(Ans,I,1)),I,1,length(Ans
sum(seq(16^IAns(I+1),I,0,dim(Ans) - 1
to use: write the hex number as a string, press enter, then run the program.
Edit: this is smaller:
Code: sum(seq(16^(I-1)(1+inString("0123456789ABCDEF",sub(Ans,I,1))),I,1,length(Ans
Only 1 line!
Last edited by Guest on 30 Nov 2003 04:23:35 pm; edited 1 time in total |
|
Back to top |
|
|
|