Created
January 17, 2014 22:08
-
-
Save red-noise/8482636 to your computer and use it in GitHub Desktop.
Hex to Binary digits
This file contains 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> | |
#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