i need to know the function that converts the binary format into an Integer using C language,for example the header file has 4 bytes,i want to convert the 4 bytes into integer.
Asked
Active
Viewed 1,901 times
1 Answers
-1
In c you can look at the same piece of memory in different way's. for example you can do a thing like this.
#include <stdio.h>
int main(int argc, char *argv[]) {
unsigned char buf[8];
buf[0] = 1;
buf[1] = 0;
buf[2] = 2;
buf[3] = 14;
int *x = (int *)buf;
printf("%lu\n",sizeof(int));
printf("%x\n",*x);
}
But it does depend on the endianness of your binary file format and the endianness of the machine being the same.

Remco Greve
- 129
- 1
- 7