Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10215
Posted: 06:05am 07 Jul 2016
Copy link to clipboard
Print this post
Assuming 0997D8738A is a string
i.e. s$="0997D8738A"
then
dim integer i=val("&H"+s$)
works perfectly on the Micromite. It won't work properly on the Maximite as the number is too big to be held accurately as a floating point numberEdited by matherp 2016-07-08
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2932
Posted: 06:11am 07 Jul 2016
Copy link to clipboard
Print this post
As a consideration: I would have a FOR i = 1 TO LEN(xxx$)...NEXT i loop where xxx$ is the Hex string input you wish to convert. NOTE: check len(xxx$)>0 first!
Then, starting at right hand side (using MID$(xxx$,len(xxx$)+1-i,1) in the above For..Next loop), take each character and convert to a decimal value between 0 and 15 (i.e. call a Sub with 16 Case Selects). Multiply this value (between 0 and 15, inclusive) by 2^(i-1) where i = position in xxx$.
This will achieve answer, but there are other ways too . . . .
WW
I just knew Peter would beat me to it!!Edited by WhiteWizzard 2016-07-08
2001cpx Regular Member Joined: 03/10/2013 Location: CanadaPosts: 59
Posted: 07:03am 07 Jul 2016
Copy link to clipboard
Print this post
I fell off my chair ..... I made a very complicated multiplication routine that was not working, A big thanks !!
RESOLVED
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667
Posted: 10:21am 07 Jul 2016
Copy link to clipboard
Print this post
Wo,
If was a dead heat I'd still give it to Peter in Simplicity.
My immediate thought was also pull the string apart & multiplying the digits by powers of 2.
Cheers.
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2932
Posted: 08:27pm 07 Jul 2016
Copy link to clipboard
Print this post
I agree, but only if needing this for a MicroMite; however note 2001cpx's possible requirement for a MaxiMite too
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10215
Posted: 10:21pm 07 Jul 2016
Copy link to clipboard
Print this post
My code will work on a Maximite just as well as on a Micromite.
The issue on a Maximite is that all numbers are stored as floating point with a 24-bit mantissa. The number in 2001cpx's example needs more bits than that to be stored accurately. It doesn't matter what technique is used to do the conversion the limitation still applies
WhiteWizzard Guru Joined: 05/04/2013 Location: United KingdomPosts: 2932
Posted: 10:29pm 07 Jul 2016
Copy link to clipboard
Print this post
@matherp
In simple terms, what is the biggest HEX number (either in terms of length, or value) that will give an accurate result.
I would try out, but all my Maxi's are still in boxes (somewhere ).
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10215
Posted: 10:34pm 07 Jul 2016
Copy link to clipboard
Print this post
24-bits = 6 HEX digits
I can't remember if the mantissa has a sign bit so it may be &H7FFFFF is the biggest positive number
Of course bigger numbers can be stored with loss of accuracy
e.g. &H7FFFFFxxxxxxx
where the x values aren't usedEdited by matherp 2016-07-09
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2431
Posted: 03:00am 08 Jul 2016
Copy link to clipboard
Print this post
what we need is some kind soul to help geoff out by back-porting the micromite code to run on the maximite, complete with the vga output of course