This is one of the way to find the binary value of the given number.
#include #include main() { int no k p 1; long int bin 0; clrscr(); puts( Enter any number to find the binaryn ); scanf( d &no); dno no;
while(n) { k no 2; bin bin + p * k; p p * 10; no no / 2; } puts( ************************************n ); printf( dThe given number is : dno); printf( l The binart format is : bin); puts( n*********************************** ); }
/*a very simple solution*/ #include<stdio.h> #include<conio.h> void main() { char ch; int i k d 1 sum 0; printf("enter the chracter"); scanf(" c" &ch); i ch; while(i> 1) { k i 2; sum sum+k*d; i i/2; d d*10; } printf(" binary is d" sum); getch(); }
Here is a simple code which will just get each bit of the char by AND operation
int main () { char a; int i j; printf("Enter a charn"); scanf(" c" &a); printf("The binary value of c " a); for (i 0 j 128; i<8; i++ j>> 1) { if ((a & j)) { printf("1"); } else { printf("0"); } } fflush(stdin); getchar(); }