LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Questions about HEX$()

Root / Programming Questions / [.]

Giant_GamerCreated:
Hello, I was working on an exercise (making a Hexadecimal calculator) and quickly found the HEX$ function. I can convert two numbers into hex, and print the result in hex INPUT NUM1 NUM1$=HEX$(NUM1) INPUT NUM2 NUM2$=HEX$(NUM2) NUM3=NUM1+NUM2 NUM3$=HEX$(NUM3) ? NUM1$;"+";NUM2$;"=";NUM3$ But when it came to attempting to reverse the process (inputting a Hex number, and getting a hex or decimal number) I got stuck. I attempted writing the Input for a Hex number and adding the string together. There seems to be no command for returning a Hexadecimal value back to a decimal.(probably I'm just not familiar with the terminology used, since I am still learning this stuff) So I think my main problem is that the output of the HEX$ is a string, and not a number. So I then attempted (mostly for fun) to try and combine the TIME$ and HEX$,(mostly because they are both strings) but that fell flat. Maybe there is something I can do to return the Hours, Minutes & Seconds as individual numbers and separately convert them into hex, and print them out together. I know I am missing something here, maybe some magical command to change a string into a decimal? Thanks for any help given.

To turn a hex string into a decimal number is actually very easy.
NUMBER%=VAL("&H"+HN$)
Keep in mind that the &H prefix only works with integers.

To turn a hex string into a decimal number is actually very easy.
Where does this line come from?

THANKS!
INPUT NUM4$
NUM4=VAL("&H"+NUM4$)
PRINT NUM4
I entered 1B, and was told 27. Now I'll get to work finishing the calculator. (I noticed the BBcode code command this time)

As for the TIME$ to HEX$ thing, I tried the following...
@LOOP
A$=TIME$
A=VAL(A$)
B$=HEX$(A)
CLS
? A$
? B$
VSYNC 2
GOTO @LOOP
The 1st printed line displayed the time correctly The 2nd printed line prints out a 0. When tested the 3rd line A=VAL(A$) returns a 0. I'm guessing that this is from the two colons in the HH:MM:SS format from the TIME$ causing an error. Could the VAL command be used to select part of the string, and not the whole. If so, how would that work? Maybe something similar to the Locate command? Thanks again if you are able to help. :D

I'm not sure if the VAL command allows you to omit part of the string. I believe it doesn't, but thankfully, that's what we have MID$ for!
A$=TIME$
A=VAL(MID$(A$,0,2))
?A$
?A
That code should be right. You can also then shift the MID$ to do the minutes and seconds by changing the 0 to a 2 or 4 (or 1 and 3, can't remember how MID$ reads the string).

Use TMREAD OUT H,M,S

To turn a hex string into a decimal number is actually very easy.
Where does this line come from?
I'm not sure what you're trying to say.

Use TMREAD OUT H,M,S
Yeah, what he said (but didn't explain.) TMREAD is an OUT instruction: it returns multiple values into multiple variables. The purpose of TMREAD is to take a HH:MM:SS formatted time string and return the hour, minute, and second as numbers. If you don't give it a time string, it automatically uses TIME$. For example:
VAR HOUR%,MINUTE%,SECOND%
TMREAD OUT HOUR%,MINUTE%,SECOND%
PRINT HOUR%,MINUTE%,SECOND%

Hey, Thanks for all the help! I'm still debugging and cleaning it up, but I have a working Hexadecimal Clock with a digital clock display. I'll probably upload it on the weekend when my 3DS can get connected to the Internet. It's more of a screen saver then anything else, but someone crazy like me might like it. (Guess2 also should be updated with minor bug fix and a few small changes, I've also made a Rock Paper Sissors AI that is almost ready to be publicly uploaded too.) Thanks again!

My Hexclock program is finally available, and is @v4.1 http://smilebasicsource.com/page?pid=1493 I wouldn't have improved it with out your help! Thanks again.