PDA

View Full Version : Splitting numbers and recombining them(EEPROM Error)



selbstdual
- 3rd June 2007, 01:23
Math issue

I wrote the following numbers to the eeprom
Position 31 till 40 (included)


2118: 00 00 00 00 00 00 00 03 ........ (Position 24 - 31)
2120: 02 02 06 04 00 03 02 00 ........ (Position 32 - 39)
2128: 01 10 27 64 00 00 00 00 ..'d.... (Position 40 - 47)


Then I wrote the following



READ 31, TenThousand
READ 32, Thousand
READ 33, Hundred
REAd 34, Ten
READ 35, One

READ 36, BThousand
READ 37, BHundred
READ 38, BTen
READ 39, BOne

Numbers = (TenThousand * 10000) + (Thousand * 1000) + (Hundred * 100) + (Ten * 10) + One
B = (BThousand * 1000) + (BHundred * 100) + (BTen * 10) + BOne

WRITE 41, Numbers.Byte0
WRITE 42, Numbers.BYte1

WRITE 43, B.Byte0
WRITE 44, B.Byte1


Result - as seen in the code above - is for numbers 10 and 27 and for B 64 and 00.

But being combined and converted to decimal numbers this is not 32264 and 320.

Why ?

Darrel Taylor
- 3rd June 2007, 02:33
Here's my guess...

You have all of the variables - TenThousand, Thousand, Hundred etc. declared as BIT instead of BYTE?



DEC 3 2 2 6 4
BIN 0011 0010 0010 0110 0100
Bitvar 1 0 0 0 0
multiplier 10,000 1,000 100 10 1
------ ----- ---- ---- ----
10,000 0 0 0 0
HEX = 2710h

DEC 0 3 2 0
BIN 0000 0011 0010 0000
Bitvar 0 1 0 0
multiplier 1,000 100 10 1
------ ----- ---- ----
0 100 0 0
HEX = 0064h

selbstdual
- 3rd June 2007, 06:40
Yes, it works after this change.