Number split Math (Simple I guess)

Status
Not open for further replies.

secretagent

New Member
I dont know how to do this, Im using a PIC microcontroller with a 16bit timer and need to split this number into seperate numbers themselves to display on the LCD....


this number can vary from 0-65535

Use these variables please:

A=ones
B=tens
C=huns
D=thousands
E=tenthou

Please help me with this equation, aswell, if you know C you may write it in C....

Thankyou guys so much! My math is not that well...
 
Last edited:
To convert from binary to BCD, you write a programme to do the following:-

If the number is > one thousand, then subtract one thousand (in binary of course) from the number & if necessary, repeat until the remainder is < one thousand. Count the number of times the subtraction is done. This counts the number of thousands.

If the number is > one hundred, then subtract one hundred from the number & if necessary, repeat until the remainder is < one hundred. . Count the number of times the subtraction is done. This counts the number of hundreds.

Then do the same for ten.

Once the remainder is < ten, then that is saved as the Units digit.
 
ok so lets say its 40056?

thou=40056-10000
thousandcount+1
if thou is greater than 10000 then thou=10000
thousandcount+1
ETC... ????
 
Does this apply to Hi-Tech C18???

result=TMR1;
itoa(result);

I don't understand where would the resuly be placed? Can you give me a link with information of the use with this function?
 
This is a little to complicated for me as i am a beginner im going with ljcox's idea first... Thanks for all the help guys!
 
ok so lets say its 40056?

thou=40056-10000
thousandcount+1
if thou is greater than 10000 then thou=10000
thousandcount+1
ETC... ????
X = 40056 - 10000 = 30056

Ten thousand Count = 1

X = 30056 - 10000 = 20056

Ten thousand Count = 2

X = 20056 - 10000 = 10056

Ten thousand Count = 3

X = 10056 - 10000 = 56

Ten thousand Count = 4

Remainder is < 10000

Remainder is < 1000

Remainder is < 100 & > 10

X = 56 - 10 = 46

Tens count = 1

X = 46 - 10 = 36

Tens count = 2

X = 36 - 10 = 26
Tens count = 3

X = 26 - 10 = 16

Tens count = 4

X = 16 - 10 = 6

Tens count = 5

Remainder = 6 which is < 10

So The BCD digits are 4, 0, 0, 5, 6
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…