Skip to content

Instantly share code, notes, and snippets.

@red-noise
Created January 17, 2014 22:08
Show Gist options
  • Save red-noise/8482636 to your computer and use it in GitHub Desktop.
Save red-noise/8482636 to your computer and use it in GitHub Desktop.
Hex to Binary digits
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,k;
int h[4];
char s;
i=3;
k=0;
printf("Insert value:");
scanf(" %c",&s);
if(s>='0' && s<='9')
k=s-'0';
else
k=s-'A'+10;
while (k>0 && i>=0)
{
h[i--]=k%2;
k=k/2;
}
while(i>=0)
h[i--]=0;
printf("Hex interpretation of %c is:",s);
for(i=0; i<4; i++)
printf("%d",h[i]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment