I'm converting input decimal value into hex and then I want to shift that value as below:
So if 51200 converts to hex: 0000 c800
Now I want to shift this value by 2 hex digits (8 bits): 00c8 0000
This is all because I'm trying to pass converted and shifted value into a microcontroller register which needs;
32 bits = 24+8 (24 bits integer part, 8 bits decimal places)
Here is my code where I'm getting the output as 0x0000C800 but as I said I want now shift this value by eight bits to get 0x00C80000
void PrintHex32( uint32_t data) // prints 32-bit data in hex with leading zeroes
{
char tmp[16];
uint16_t LSB = data & 0xffff;
uint16_t MSB = data >> 16;
sprintf(tmp,"0x%.4X%.4X%", MSB, LSB);
Serial.println(tmp);
// Serial.println(temp2);
Serial.println("************");
}
EDIT: trial two as per David comment; so I try to convert this before conversion but no luck! output: 0x00000000
void PrintHex32( uint32_t data) // prints 32-bit data in hex with leading zeroes
{
uint32_t data2 = data2<< 8;
char tmp[16];
uint16_t LSB = data2 & 0xffff;
uint16_t MSB = data2 >> 16;
sprintf(tmp,"0x%.4X%.4X%", MSB, LSB);
Serial.println(tmp);
// Serial.println(temp2);
Serial.println("************");
}
Any help kindly appreciated as I'm burning out!
User contributions licensed under CC BY-SA 3.0