• Welcome to Valhalla Legends Archive.
 

c programing homework help

Started by rice, September 27, 2009, 01:19 AM

Previous topic - Next topic

rice

im a beginner and is having a bit of trouble doing this hw question, if any of you could give me a hint or help me out it would be really thankful.

basically i need to use bitwise operators to write a program that does the following; ask user to input a char then display its binary value and ascii value, then ask user to enter a specific bit of that char which the program will check, the vavlue of the bit entered by the user will then be shown, this is what the program should look like:



----------------
   enter a char:
     binary value of char: 000001010
              ascii value of char: 54

enter a bit for the program to check: 5
the bit value is: 1
---------------------


this is what i have so far(please dont laugh i know i suck):

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int main()
{

char input;
puts("enter a char: ");
scanf("%c", &input);



printf("ascii value of char is: %d", input);


getch();
return 0;
}



thank you in advance:

Final

Look up Type Casting in c good luck.

Camel


printf("binary: ");
for(i = 7; i >= 0; i--)
    putc((input >> i) & 0x01 ? '1' : '0');