uint8 val; // The value you want to convert
uint16 bcdval; // The converted value
uint8 d0, d1, d2; // the 3 decimal figures used to write a 0 ~ 255
d2 = val / 100;
val -= 100 * d2;
d1 = val / 10;
d0 = val % 10;
bcdval = d2 << 8 + d1 << 4 + d0;
I want to convert a hex value(8 bit) to BCD.Actually we do add 6 to the hex values that has lower nibbles ranging from 'A' to 'F' only or we add 6 to all the hex values greater than 0x09?
Thanking you & Regards,
Jerin.
What is the logic behind shifting the MSB to the right by 4?Also the initial values of the 2 char variables must be 0 rite?MSD += ((HEXVal & 0xF0) >> 4);
Here each time when MSD increments do we have to initialize MSD to 0 after it has incremented & added?if(LSD > 10) // adjust if A - F
{
LSD -= 10;
MSD++;
}
while(1) {
// Insert your loop code here.
}
Why not doing:
if(a > 0x99) {
temp = 0;
i = 0;
a = 0;
}
else { // This area is not entered if a > 0x99
if(a == val[i]) {
a += 6;
i++;
}
keyval = a;
keyval = keyval/16; //MSB
keytemp = a%16; //LSB
if(keytemp > 0x09) {
keytemp -= 10;
keyval++;
}
keyval = keyval<<4;
temp = keyval + keytemp;
}
key = temp;
PORTD = key;
Is there any other function for goto in C?
Regards,
Jerin.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?