Thread: converting variable to bits?

  1. #16
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by draggy
    coding example please....
    Read the FAQ on bit shifting. While you're at it, read the FAQ on why void main is wrong.


    Quzah.
    Hope is the first step on the road to disappointment.

  2. #17
    Registered User
    Join Date
    Jul 2005
    Posts
    39
    Quote Originally Posted by quzah
    Read the FAQ on bit shifting. While you're at it, read the FAQ on why void main is wrong.


    Quzah.
    Code:
    int main()
    {
    	unsigned char a = 'a';
    	unsigned char c = 0;
    	unsigned char b[8];
    	char mask = 1;
    	int i;
    	
    	for(i = 8; i > 0; i--)
    	{
    		printf("%d", a & mask);
    		b[i - 1] = a & mask;
    		a >>= 1;
    	}
    
    	printf("\n");
    
    	for(i = 0; i < 8; i++)
    	{
    		c |= b[i];
    		c <<= 1;
    
    		if(b[i] == 1)
    		{
    			printf("1");
    		}
    		else
    		{
    			printf("0");
    		}		
    	}
    
    	printf("\n%c\n", c);
    
    	return 0;
    }
    most important part
    Code:
    c |= b[i]; //means c = c | b[i];
    c <<= 1;//means c = c << 1;
    nothing change still get the same old error result....

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Fascinating I'm sure, but what exactly do you expect to get? People sure don't know how to ask people to help them. Picture a conversation with someone:

    You: This doesn't work.
    Them: That's nice.
    You: Fix it.
    Them: What's wrong?
    You: This doesn't work.

    That's all well and good, but how about you actually tell us a bit more. How about we take a different turn in our conversation?

    You: This doesn't work.
    Them: That's nice.
    You: Fix it.
    Them: What's wrong?
    You: Well I input this, and I'm supposed to get this. But I don't, I get that instead.

    See how much better that is? Now you try.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Since I'm such a nice guy, here's a hint:
    most important part
    Code:
    c |= b[i]; //means c = c | b[i];
    c <<= 1;//means c = c << 1;
    ?uoy naC .tahw tuo erugif etiuq t'nac I .senil owt esoht htiw gnorw gnihtemos evah uoy ,revewoh ,trap tcerroc eht detouq evah ot mees uoY


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #20
    Registered User
    Join Date
    Jul 2005
    Posts
    39
    fixed the problem...


    Thanks

  6. #21
    Prying open my third eye.
    Join Date
    Jun 2005
    Posts
    45
    Quote Originally Posted by quzah
    Since I'm such a nice guy, here's a hint:?uoy naC .tahw tuo erugif etiuq t'nac I .senil owt esoht htiw gnorw gnihtemos evah uoy ,revewoh ,trap tcerroc eht detouq evah ot mees uoY


    Quzah.
    ahahaha

    Interesting way to get your point accross.
    "So you're one of those condescending UNIX computer users?"

    "Here's a nickel, kid. Get yourself a better computer."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Static Local Variable vs. Global Variable
    By arpsmack in forum C Programming
    Replies: 7
    Last Post: 08-21-2008, 03:35 AM
  2. Having trouble converting a variable
    By KasMage in forum C++ Programming
    Replies: 6
    Last Post: 07-14-2008, 03:43 PM
  3. variable being reset
    By FoodDude in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2005, 12:30 PM
  4. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  5. Writing binary data to a file (bits).
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-05-2004, 03:53 PM