Skip to main content
deleted 4 characters in body
Source Link
sth
  • 231.2k
  • 56
  • 288
  • 370

I was having problems converting a char array like "7c7c7d7d7d7d7c7c7c7d7d7d7d7c7c7c7c7c7c7d7d7c7c7c7c7d7c7d7d7d7c7c2e2e2e""7c7c7d7d7d7d7c7c7c7d7d7d7d7c7c7c7c7c7c7d7d7c7c7c7c7d7c7d7d7d7c7c2e2e2e" into its actual integer value that would be able to be represented by '7C'`7C' as one hexadecimal value. So, after cruising for help iI created this, and thought it would be cool to share. This

This separates the char string into its right integers, and may be helpful to more people than just me ;)

unsigned int* char2int(char *a, int len) { int i,u; unsigned int *val = malloc(len*sizeof(unsigned long)); for(i=0,u=0;i<len;i++){ if(i%2==0){ if(a[i] <= 57) val[u] = (a[i]-50)<<4; else val[u] = (a[i]-55)<<4; } else{ if(a[i] <= 57) val[u] += (a[i]-50); else val[u] += (a[i]-55); u++; } } return val; } 

Hope it helps! Cheers

I was having problems converting a char array like "7c7c7d7d7d7d7c7c7c7d7d7d7d7c7c7c7c7c7c7d7d7c7c7c7c7d7c7d7d7d7c7c2e2e2e" into its actual integer value that would be able to be represented by '7C' as one hexadecimal value. So, after cruising for help i created this, and thought it would be cool to share. This separates the char string into its right integers, and may be helpful to more people than just me ;)

unsigned int* char2int(char *a, int len) { int i,u; unsigned int *val = malloc(len*sizeof(unsigned long)); for(i=0,u=0;i<len;i++){ if(i%2==0){ if(a[i] <= 57) val[u] = (a[i]-50)<<4; else val[u] = (a[i]-55)<<4; } else{ if(a[i] <= 57) val[u] += (a[i]-50); else val[u] += (a[i]-55); u++; } } return val; } 

Hope it helps! Cheers

I was having problems converting a char array like "7c7c7d7d7d7d7c7c7c7d7d7d7d7c7c7c7c7c7c7d7d7c7c7c7c7d7c7d7d7d7c7c2e2e2e" into its actual integer value that would be able to be represented by `7C' as one hexadecimal value. So, after cruising for help I created this, and thought it would be cool to share.

This separates the char string into its right integers, and may be helpful to more people than just me ;)

unsigned int* char2int(char *a, int len) { int i,u; unsigned int *val = malloc(len*sizeof(unsigned long)); for(i=0,u=0;i<len;i++){ if(i%2==0){ if(a[i] <= 57) val[u] = (a[i]-50)<<4; else val[u] = (a[i]-55)<<4; } else{ if(a[i] <= 57) val[u] += (a[i]-50); else val[u] += (a[i]-55); u++; } } return val; } 

Hope it helps!

Source Link

I was having problems converting a char array like "7c7c7d7d7d7d7c7c7c7d7d7d7d7c7c7c7c7c7c7d7d7c7c7c7c7d7c7d7d7d7c7c2e2e2e" into its actual integer value that would be able to be represented by '7C' as one hexadecimal value. So, after cruising for help i created this, and thought it would be cool to share. This separates the char string into its right integers, and may be helpful to more people than just me ;)

unsigned int* char2int(char *a, int len) { int i,u; unsigned int *val = malloc(len*sizeof(unsigned long)); for(i=0,u=0;i<len;i++){ if(i%2==0){ if(a[i] <= 57) val[u] = (a[i]-50)<<4; else val[u] = (a[i]-55)<<4; } else{ if(a[i] <= 57) val[u] += (a[i]-50); else val[u] += (a[i]-55); u++; } } return val; } 

Hope it helps! Cheers