-
-
Save trickre/5c6a32846675f965cfb4101532eceeb2 to your computer and use it in GitHub Desktop.
Print bits of unsigned char
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
//This program enable you to see bit of variable(char and int). | |
#include <stdio.h> | |
void printbits(unsigned char v) { | |
int i; // for C89 compatability | |
for(i = 7; i >= 0; i--) putchar('0' + ((v >> i) & 1)); | |
} | |
void printbits_int(int v) {//for 32bit variable | |
int i,j; | |
for(i=8*sizeof(int)-1; i >= 0; ) { | |
for(j=4; j>0; j--) { | |
putchar('0' + ((v >> i) & 1)); | |
i--; | |
} | |
putchar(' '); | |
} | |
} | |
void main(){ | |
printf("This program enable you to see bit of variable.\n"); | |
printf("Ener one character you want see its bit(= ascii code).\n"); | |
char x=getchar(); | |
printbits(x); | |
printf("\nEner variable(int) you want see its bit.\n"); | |
int y=0; | |
scanf("%d",&y); | |
printbits_int(y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment