Continue to Site

# 16f628A how to convert Hex to Decimal

Status
Not open for further replies.

#### Hakachukai

##### New Member
Does anyone know any good, simple way to do this?

I just need to take hex values and convert them to decimal for display purposes.

I'm hoping that there is a simple way to do it. I can think of a few not so simple... not efficient ways to do it.

Also... how can I multiply or divide a number by 1.8 ??? I need to do this for the conversion between DegC and DegF for my temperature readout.

Last edited:
I normally do this,
Code:
PutDecimal	clrf	Decimal100
Count100s	incf	Decimal100,F
btfsc	STATUS,C
goto	Count100s
clrf	Decimal10
Count10s	incf	Decimal10,F
btfsc	STATUS,C
goto	Count10s
movwf	Units
movfw	Decimal100
call	PutChar
movfw	Decimal10
call	PutChar
movfw	Units
goto	PutChar

Call it with the value in W.

As for multiplying by 1.8, you don't. You multiply by 9 (shift left 3 times and add the original) and divide by 5. See Piclist for 8 bit divide code.

Mike.

Last edited:
Thanks!

I was going to use this process(**broken link removed**), and impliment a long hand multiplcation / division routine for floating point numbers.... but your way seems a lot easier... and a faster

converting binary to hex implies you to do the followings;
1.multiply the individual numbers by that given base i.e base 16.
2.raise their bases by begining from the last i.e.from zero to where ever the base has ended.
3.addup all the multiples by so doing a result is gotting
Good luck.

Check the LCD routines in my PIC tutorials, which do just what you want for 16 bit values.

So, I'm working on making a long hand multiplication routine for floating point numbers.

Is there a way that I can just reserve memory and have an indexable pointer to it?
Right now I'd like to use 17bit's of storage for each floating point number.

1 bit for sign
8 bits for the integer portion
8 bits for the fractional portion

That would allow me to have numbers between 1/128 and 255.9921875 ( + and - )

anyway... it's all pretty easy to do... I just need to figure out a way that I can index through the memory in a loop, instead of having to call my File reg's by name. I could do it even calling them by name... but it would be ugly and probably end up using more code space.

That is not floating point, that is known as fixed point.

To access your variables you use the FSR and INDF registers. Load FSR with the address of your variable and any read or writes to INDF will access the register pointed to by the FSR register.

Mike.

Thanks! That will come in very handy!

Good point... floating point would kind of suggest that the point moves... and mine never does.

Status
Not open for further replies.

Replies
15
Views
825
Replies
7
Views
711
Replies
31
Views
5K
Replies
7
Views
1K
Replies
14
Views
2K