Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:35 05 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 : uMITE 5.2 45Chr HEX$ to Decimal$

Author Message
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 10:00am 15 Nov 2016
Copy link to clipboard 
Print this post

Hi All;
Is there an algorithm to convert long HEX strings to Decimal
strings and vice verse.
My HEX string is 45 characters long.
Apparently the Decimal string is 54 or 55 characters long.
I want to also convert 135 character Binary but, of course,
this is trivial if the HEX conversions work.

I've been searching the net but no luck.
Of course, if I only had a 16 HEX characters its built into MM.

I should say, this is being used in a high precision
HEX based "Fixed Point" math calculation.

Thanks!!!
redrokEdited by redrok 2016-11-16
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1571
Posted: 01:53pm 15 Nov 2016
Copy link to clipboard 
Print this post

Hi Redrok,

this is not the answer, but did you see Peter Carnegies "BCD Arithmetic Library"? Maybe a inspiration?

Kind regards
Michael

edit:
Perhaps a look in the MMBasic source code helps (Hex$ function)?

Edited by twofingers 2016-11-17
causality ≠ correlation ≠ coincidence
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 04:13pm 15 Nov 2016
Copy link to clipboard 
Print this post

Hi Michael;
  twofingers said   Hi Redrok,
this is not the answer, but did you see Peter Carnegies "BCD Arithmetic Library"? Maybe a inspiration?

Kind regards
Michael

edit:
Perhaps a look in the MMBasic source code helps (Hex$ function)?

Yes, I'm aware of Peters "BCD Arithmetic Library" It was the inspiration
for me to look at BigNum programs. What made me try to write my own was
to use "Fixed Point" arithmetic, numbers with a fractional part.
Peters was based on integers. Also it used "Multiply" instructions
which are slower than shift and add instructions. I don't know if this
is a valid reason yet.

When writing my test codes using a single 64bit register, I noticed that
I can run the program as though it had a fractional part to the number.
What I did so far:
1. Do the standard all integer shift and add routine.
> Justify the answer by shifting all the way, 64bits, to the right.
2. Multiply only the fractional part. Left shift The Multiplicand and
Multiplier to the left. Then do the shift and add routine.
> But DON'T do the Justification shifts for the answer, I.e. 0bits.
3. Same thing but do shift to a more middle position.
> Justification of the answer is done to that central position.
Note! I haven't figured out how many justification bits are needed
yet. I did it by trial and error. I'm sure it can be calculated.

Doing it this way I can implement it as a Fixed Point arithimentic
unit like this HHHHH.hhhhhhh of any size.

I'm now extending the multiply to multiple 64bit registers.
BTW, the registers must be 2 times as long as the numbers lengths used.

Just as a test I tried to do the Taylor series SIN(x) function.
This worked tolerably well with the limited test register size I used.
besides, this can be done with only multiplies and constants. ( don't
know how to do the divide yet.)

BTW, here is an interesting computer math link:
Bit Mathematics cookbook

Since I don't consider myself a programmer, any help is appreciated.

I need to revisit Peters code to see if I can modify it for Fixed Point operation.

redrok
 
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