Jump to content
IGNORED

TI extended Basic Binary to Hex subroutine


jrhodes

Recommended Posts

Here's a code segment - probably not exactly what you're looking for, but here it is.  It assumes DEC is a DECimal input, and T(E) == 2^X for X=0 to 15 (so basically an extra conversion here from decimal to binary before then converting to hex).

 

100 BIN$="" :: FOR E=15 TO 0 STEP -1
110 IF DEC>=T(E)THEN BN16$(E)="1" :: DEC=DEC-T(E)
120 BIN$=BIN$&BN16$(E):: NEXT E
130 HEX$="" :: FOR E=3 TO 0 STEP -1
140 IF SEG$(BIN$,-4*E+13,4)="1111" THEN HX$(E)="F"
150 IF SEG$(BIN$,-4*E+13,4)="1110" THEN HX$(E)="E"
160 IF SEG$(BIN$,-4*E+13,4)="1101" THEN HX$(E)="D"
170 IF SEG$(BIN$,-4*E+13,4)="1100" THEN HX$(E)="C"
180 IF SEG$(BIN$,-4*E+13,4)="1011" THEN HX$(E)="B"
190 IF SEG$(BIN$,-4*E+13,4)="1010" THEN HX$(E)="A"
200 IF SEG$(BIN$,-4*E+13,4)="1001" THEN HX$(E)="9"
210 IF SEG$(BIN$,-4*E+13,4)="1000" THEN HX$(E)="8"
220 IF SEG$(BIN$,-4*E+13,4)="0111" THEN HX$(E)="7"
230 IF SEG$(BIN$,-4*E+13,4)="0110" THEN HX$(E)="6"
240 IF SEG$(BIN$,-4*E+13,4)="0101" THEN HX$(E)="5"
250 IF SEG$(BIN$,-4*E+13,4)="0100" THEN HX$(E)="4"
260 IF SEG$(BIN$,-4*E+13,4)="0011" THEN HX$(E)="3"
270 IF SEG$(BIN$,-4*E+13,4)="0010" THEN HX$(E)="2"
280 IF SEG$(BIN$,-4*E+13,4)="0001" THEN HX$(E)="1"
290 IF SEG$(BIN$,-4*E+13,4)="0000" THEN HX$(E)="0"
300 HEX$=HEX$&HX$(E):: NEXT E

 

  • Like 6
Link to comment
Share on other sites

Here's something to get you started. 😉
 

100 PRINT
110 INPUT "DEC VAL: ":D
120 CALL CONVERT((D),16,"HEX VAL: ")
125 CALL CONVERT((D),8,"OCT VAL: ")
130 CALL CONVERT((D),2,"BIN VAL: ")
140 GOTO 100
200 SUB CONVERT(D,B,T$)
210 R$=""
220 C=D-INT(D/B)*B
230 IF C<10 THEN R$=CHR$(C+48)&R$ ELSE R$=CHR$(C+55)&R$
240 D=INT(D/B)::IF D>0 THEN 220
250 PRINT T$;R$
260 SUBEND

 

  • Like 9
Link to comment
Share on other sites

1 hour ago, sometimes99er said:

Here's something to get you started. 😉

Hey, now that is clean - and interesting approach.  I had to look step through it with an example number.   I'm usually too bullheaded in my strict procedural approach to come up with something so tidy.

Edited by WhataKowinkydink
  • Like 3
Link to comment
Share on other sites

Binary to Hex ... 😊
 

100 c$="0000-0-0001-1-0010-2-0011-3-0100-4-0101-5-0110-6-0111-7-1000-8-1001-9-1010-A-1011-B-1100-C-1101-D-1110-E-1111-F"
110 accept validate("01") size(8):b$ ::b$=rpt$("0",8)&b$::b$=seg$(b$,len(b$)-7,8)::b1$=seg$(b$,1,4)::b2$=seg$(b$,5,4)
120 print :seg$(c$,pos(c$,b1$,1)+5,1)&seg$(c$,pos(c$,b2$,1)+5,1)

  

  • Like 7
  • Haha 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...