How to extract the number 0145525000 from the array 0x00, 0x50, 0x52, 0x45, 0x01 in C language?
#include <stdio.h>
int main()
{
uint8_t arr[] = {0x00, 0x50, 0x52, 0x45, 0x01};
uint32_t number = 0;
// Sorry i dont know how to solve this
printf("Number: %d\n", number);
return 0;
}
It is necessary to convert from the last element to zero into one unsigned integer?
The hexadecimal constant
0145525000that will be more correctly to write like0x0145525000contains at least9hexadecimal digits (if to ignore the leading0) that can not be represented in an object of the typeuint32_t. The variablenumbershould be declared as having typeuint64_t.Now what you need is to write a loop that will store hexadecimal values present in the array
arrin the reverse order to the variablenumber.Here you are.
The program output is
The statement within the for loop
may be rewriten also like