See you are considering one bit of bit1, and printing it as signed integer.
So what i think is that '1' bit will be treated as 1111 1111 while treating
it as Signed Integer, and this is the binary representation of
-1. Hence the result.

If you write it as unsigned int bit1:1, the result is 122. So my argument is
correct.

Try this and let me know.

Correct me If m wrong.
Sanju
:)



On Sat, Aug 20, 2011 at 8:44 PM, sukran dhawan <sukrandha...@gmail.com>wrote:

> only one bit is reserved for it.so the binary representation is 1.since
> only one bit is present,
> that bit becomes sign nit and hence -1
>
> On Sun, Aug 21, 2011 at 8:07 AM, saurabh singh <saurab...@gmail.com>wrote:
>
>> Read bit field....
>>
>>
>> On Sun, Aug 21, 2011 at 2:44 AM, Nitin <coolguyinat...@gmail.com> wrote:
>>
>>> #include<stdio.h>
>>> main()
>>> {
>>>   struct value
>>> {
>>>   int bit1:1;
>>> int bit2:4;
>>> int bit3:4;
>>> }bit={1,2,2};
>>> printf("%d%d%d",bit.bit1,bit.bit2,bit.bit3);
>>> }
>>>
>>> output is -1,2,2;
>>> can anybody tell me the reason that y it is giving -1 ??
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Saurabh Singh
>> B.Tech (Computer Science)
>> MNNIT ALLAHABAD
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to