Created
January 31, 2010 21:59
-
-
Save anonymous/291263 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
//takes a string to read, a byte array to put stuff into, and the number of | |
//bytes requested (strlen(input)/2) | |
void compute(char *input, int *into, int num) { | |
int i; | |
char buf[3]; buf[2] = '\0'; | |
for(i=0; i<num*2; i+=2) { | |
buf[0] = input[i]; | |
buf[1] = input[i+1]; | |
into[i==0 ? 0 : i/2] = strtol(buf,0,16); | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
if(argc < 2) { | |
fprintf(stderr, "put the numbers as first argument.\n"); | |
return 1; | |
} | |
char *input = argv[1]; | |
//the number of bytes we want in the end | |
int num = 6; | |
//make the result array the correct size | |
int result[num]; | |
//send the input to compute, which fills result with the numbers | |
compute(input, &result[0], num); | |
int i = 0; | |
for(i = 0; i < 6; i++) { | |
printf("%02x\n", result[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment