matyyyy
matyyyy

Reputation: 387

Creating binary files from hex in C

I've used:

sprintf(hex, "%02x", (unsigned int) buffer[0] & 0xff);

to get hexadecimal representation of binary file. After that I save this representation to txt file.

Now I' d like to execute inverse operation. How can I create binary file from my hex data?

Upvotes: 1

Views: 491

Answers (1)

Timothy Jones
Timothy Jones

Reputation: 22125

sscanf() will let you do the inverse of sprintf()

int output;  
int we_read_an_integer = sscanf(inputString, "%02x", &output);

Repeat as necessary.

Upvotes: 4

Related Questions