I have two integer values say a and b. The values of a and b range between 0 to 9999. Both of the values have to be passed into uint8_t array[4];
The array format
uint8_t array[4] = { 0x00, 0x00, //value of a should come here (hex format)
0x00, 0x00}
0x00 represents the hex format. (i.e., if a = 65535 is 0xffff)
I tried using sprintf to hold the value but I was not able to get an exact conversion. The program I did works for int but not uint8_t.
Any help on this would be great.
Thanks an regards
Niranjan
Please provide the code you're working with. You seem to be confused. All numbers the processor works with are binary. Hex, decimal, etc are just human-readable representations of the binary numbers. 'sprintf()' produces ASCII character strings, which is probably not what you want.
int a = any number between (0 - 9999);
int b = any number between (0 - 9999);
uint8_t adData1[4] = {
/* a / 0x00,0x00,
/ b */ 0x00,0x00
}
P.S. I realized i am spliting integer (2 bytes) into uint8_t one byte and sending it. But I dont know the syntax in this case.
This is how the code format is. The adData1 values are displayed in decimal in my other device(mobile phone). I cannot modify that since I don't have the code base for that.
It's a huge file. That's why I could not share it.
Regards
Niranjan
Niranjan_ravi:
P.S. I realized i am spliting integer (2 bytes) into uint8_t one byte and sending it.
How are you "sending it"? What is the signature of the function you're calling? You may not need to "convert" anything. If you're talking about RF69, LORA, nRF24L01+, etc., then you only need a properly cast pointer.