-2

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.

mike
  • 7
  • 3
  • 3
    Can you provide information about your current attempt at doing this? – starlight Apr 15 '17 at 09:01
  • 2
    Possible duplicate of [Convert Bytes to Int / uint in C](http://stackoverflow.com/questions/12240299/convert-bytes-to-int-uint-in-c) – msc Apr 15 '17 at 09:19

1 Answers1

-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