internetuser2k12
Banned
- Joined
- Jul 25, 2012
- Messages
- 1,192
- Helped
- 171
- Reputation
- 342
- Reaction score
- 162
- Trophy points
- 1,343
- Activity points
- 0
Hello!
I need a n explanation of
see post 12 at http://www.mikroe.com/forum/viewtopic.php?p=84795
He is using byear as a variable which increments from 0 to 99 decimal
He is then converting for eg: decimal 99 to bcd using the above statement
bYear/10 = 99/10 = 0x09 or d9 {integer division)
(bYear / 10) << 4) = 9 << 4 = 0x90 or d144
(bYear / 10) << 4) & 0xC0) = 0x90 & 0xC0 = 0x80 or d128
bYear/10 = 0x09 or d9
(bYear / 10) * 10) = d9 * 10 = d90 or 0x5A
(bYear-(bYear / 10) * 10) = d99 - d90 or 0x63 - 0x5A = d9 or 0x09
((bYear-(bYear / 10) * 10) & 0b00001111) = d9 or 0x09
(((bYear / 10) << 4) & 0xC0) + ((bYear-(bYear / 10) * 10) & 0b00001111) = d128 + d9 or 0x80 + 0x09 = d137 or 0x89
How is he writing 0x89 or d137 instead of 0x99 or dfor year 99. or how is writing d153 for year 99?
i think it should be
so that,
(bYear/10) = 99/10 = d9 or 0x09
((bYear/10)<<4) = 0x09 << 4 or d9 << 4 = 0x90 or d144
(bYear%10) = 99%10 = d9 or 0x09
(((bYear/10)<<4) + (bYear%10)) = 0x90 + 0x09 = 0x99 or d144 + d9 = 153
Isn't the second equation right?
Isn't this equation
wrong for Decimal to BCD Conversion?
I need a n explanation of
Code:
bYear = (((bYear / 10) << 4) & 0xC0) + ((bYear-(bYear / 10) * 10) & 0b00001111);
He is using byear as a variable which increments from 0 to 99 decimal
He is then converting for eg: decimal 99 to bcd using the above statement
bYear/10 = 99/10 = 0x09 or d9 {integer division)
(bYear / 10) << 4) = 9 << 4 = 0x90 or d144
(bYear / 10) << 4) & 0xC0) = 0x90 & 0xC0 = 0x80 or d128
bYear/10 = 0x09 or d9
(bYear / 10) * 10) = d9 * 10 = d90 or 0x5A
(bYear-(bYear / 10) * 10) = d99 - d90 or 0x63 - 0x5A = d9 or 0x09
((bYear-(bYear / 10) * 10) & 0b00001111) = d9 or 0x09
(((bYear / 10) << 4) & 0xC0) + ((bYear-(bYear / 10) * 10) & 0b00001111) = d128 + d9 or 0x80 + 0x09 = d137 or 0x89
How is he writing 0x89 or d137 instead of 0x99 or dfor year 99. or how is writing d153 for year 99?
i think it should be
Code:
bYear = (((bYear/10)<<4) + (bYear%10));
so that,
(bYear/10) = 99/10 = d9 or 0x09
((bYear/10)<<4) = 0x09 << 4 or d9 << 4 = 0x90 or d144
(bYear%10) = 99%10 = d9 or 0x09
(((bYear/10)<<4) + (bYear%10)) = 0x90 + 0x09 = 0x99 or d144 + d9 = 153
Isn't the second equation right?
Isn't this equation
Code:
(((bYear / 10) << 4) & 0xC0) + ((bYear-(bYear / 10) * 10) & 0b00001111)
Last edited: