Showing posts with label character to ascii bits. Show all posts
Showing posts with label character to ascii bits. Show all posts

Tuesday, February 2, 2010

character to ascii bits

#include
#include
void main()
{
int i,arr[8],j;
char ch;
FILE *fp; // file pointer initialization
fp=fopen("c:\\priyu.txt","r"); //open in read mode
ch=fgetc(fp);
clrscr();
// printf("enter character :");
// scanf("%c",&ch);
printf("%c=%d in binary:",ch,ch);
for(i = 7,j=0; i>=0; i--,j++)
{
// printf("\n%d",(1< //if not 0 then if or else
if((1< {
printf("1");
arr[j]=1;
}
else
{
printf("0");
arr[j]=0;
}
}
printf("\n");
for(j=0;j<=7;j++)
{
printf("%d",arr[j]);
}
//find first four bits
printf("\nfirst four bits of character:");
for(j=0;j<=3;j++)
{
printf("%d",arr[j]);
}
printf("\n");
getch();
}