Thread: binary value

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    62

    binary value

    i am a neb and i really need help on this whe i type in charater A the program gives me 66, which is wrong it should be 65.

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    void getBinary(char ch);
    /*int getBit(char ch,int x) ;
    void changeBit(char ch, int x);
    */
    int main(int argc, char* argv[])
    
    {
    	char a;
    
    	printf("Enter a character");
    	scanf("%c",&a);
    	getBinary(a);
    	//printf("the new character after the bit change is %i",ch);
    	getch();
    
    	return 0;
    }
    
     void getBinary(char ch)
     {
    	int mask = 128;
    	int i;
    	printf("\nThe binary value of %c is:");
    	for (i=0; i <=8; i++)
    	{
    		if ((ch &mask)!=0)
    			printf("1");
    		else
    			printf("0");
    		ch=ch<<1;
    	}
    
     }
    /* int getBit(char ch,int x)
     {
    
     }
     void changeBit(char ch, int x)
     {
    
     }
     */

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Did you notice that you printed nine bits?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 02:02 PM
  2. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM