Skip to content

Instantly share code, notes, and snippets.

@aattk
Created May 22, 2022 16:10
Show Gist options
  • Select an option

  • Save aattk/284323418afcff14880e4ec083fa90c5 to your computer and use it in GitHub Desktop.

Select an option

Save aattk/284323418afcff14880e4ec083fa90c5 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int hex2int(char * hex,int size)
{
int sonuc,sayac = 0,val;
while(1)
{
if (hex[sayac] != '\0')
{
if(hex[sayac]>='0' && hex[sayac]<='9')
{
val = hex[sayac] - 48;
}
else if(hex[sayac]>='a' && hex[sayac]<='f')
{
val = hex[sayac] - 97 + 10;
}
else if(hex[sayac]>='A' && hex[sayac]<='F')
{
val = hex[sayac] - 65 + 10;
}
sonuc += val * pow(16, size - sayac -1 );
sayac++;
}
else
{
break;
}
}
return sonuc;
}
int main()
{
printf("%d",hex2int("b0",2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment