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 want to know how this BCD to Decimal code works.
Should I have to give 0x99 for year 99 for bcd in the formula to get 153 decimal
i.e., (bcd >> 4) = 0x99 >> 4 = 0x09 or d9
(bcd >> 4)*10 = 0x09 * d10 = 0x90 or d144
(bcd & 0x0F) = 0x99 & 0F = 0x09 or d9
finally 0x90 + 0x09 = 0x99 or d144 + d9 = d153.
I have confusion here (bcd >> 4)*10 = 0x09 * d10 = 0x90 or d144 does it calculate 0x90 * d10 or 0x90 * 0x0A? I think it calulates 0x90 * d10 because 10 is written as 10 and not 0x10 or 0x0A. Am I right?
I want to know how this BCD to Decimal code works.
Code:
((bcd >> 4)*10+(bcd & 0x0F));
Should I have to give 0x99 for year 99 for bcd in the formula to get 153 decimal
i.e., (bcd >> 4) = 0x99 >> 4 = 0x09 or d9
(bcd >> 4)*10 = 0x09 * d10 = 0x90 or d144
(bcd & 0x0F) = 0x99 & 0F = 0x09 or d9
finally 0x90 + 0x09 = 0x99 or d144 + d9 = d153.
I have confusion here (bcd >> 4)*10 = 0x09 * d10 = 0x90 or d144 does it calculate 0x90 * d10 or 0x90 * 0x0A? I think it calulates 0x90 * d10 because 10 is written as 10 and not 0x10 or 0x0A. Am I right?