Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:23 07 Jul 2025 Privacy Policy
Jump to

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.

Forum Index : Microcontroller and PC projects : Hexadecimal to Decimal Conversion HELP!

Author Message
2001cpx

Regular Member

Joined: 03/10/2013
Location: Canada
Posts: 59
Posted: 05:38am 07 Jul 2016
Copy link to clipboard 
Print this post

Hi,

Tried in many way to Convert this Hexadecimal (for exemple):

0997D8738A that give 41202250634 in Decimal

i currently use Maximite and Micromite GCmicroboard2b


Thanks In Avandce ,i like MMbasic!!!!









"Color Maximite,(Duinomite-Mega,Mini),CGmmStick,GCmicroboard2b,Micromite + explore 64,100,LCD backpack,Lcd Backpack V2,TFT Backpack,Micromite Extreme,Armmite L,F,H,CMM2"
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 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 Kingdom
Posts: 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: Canada
Posts: 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

Thanks Matherp and WhiteWizzard!!!



"Color Maximite,(Duinomite-Mega,Mini),CGmmStick,GCmicroboard2b,Micromite + explore 64,100,LCD backpack,Lcd Backpack V2,TFT Backpack,Micromite Extreme,Armmite L,F,H,CMM2"
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 10:21am 07 Jul 2016
Copy link to clipboard 
Print this post

  matherp said  
s$="0997D8738A"

then

dim integer i=val("&H"+s$)


  WhiteWizzard said  I would have a FOR i = 1 TO LEN(xxx$)...NEXT i loop where xxx$ is the Hex string input you wish to convert.....

I just knew Peter would beat me to it!!


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 Kingdom
Posts: 2932
Posted: 08:27pm 07 Jul 2016
Copy link to clipboard 
Print this post

  Phil23 said   .... I'd still give it to Peter in Simplicity.


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 Kingdom
Posts: 10215
Posted: 10:21pm 07 Jul 2016
Copy link to clipboard 
Print this post

  Quote  however note 2001cpx's possible requirement for a MaxiMite too


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 Kingdom
Posts: 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 Kingdom
Posts: 10215
Posted: 10:34pm 07 Jul 2016
Copy link to clipboard 
Print this post

  Quote  In simple terms, what is the biggest HEX number (either in terms of length, or value) that will give an accurate result.


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 Zealand
Posts: 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


cheers,
rob :-)
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025