thanks
@Dave n Rushiraj

I think I have got the solution .  1<<5-1 will be evaluated like  1<<(5-1).
it will be 16. Now the negation of 000....10000 will be 111....01111 and
this will be my mask.

so
 for 56 -->  000....111000  & 111...01111 = 000...101000   => 40.
 for 64 -->  000...1000000 & 111...01111 = 000...1000000 = > 64
 for 127--> 000... 1111111 & 111...01111 = 000...1101111 => 111

I hope this is correct .
Please correct me if I am wrong.

Thanks,
Rajesh


On Sat, Nov 24, 2012 at 8:36 PM, Dave <dave_and_da...@juno.com> wrote:

> @Rajesh: In binary, mask = 111...100000 (with 4-byte ints, this is 27
> 1-bits followed by 5 0-bits). The logical product of num with mask zeros
> out the low order 5 bits while retaining the high order 27 bits. Thus, res
> is num truncated to the largest multiple of 32 that does not exceed num. 56
> = (1*32 + 24) goes to 1*32 = 32, 64 (=2*32 + 0) stays at 2*32 = 64, and 127
> (=3*32 + 31) goes to 3*32 = 96.
>
> Dave
>
> On Saturday, November 24, 2012 2:45:24 AM UTC-6, rajesh pandey wrote:
>
>> void dosomething(int num)
>> {
>> int mask=~(1<<5-1);
>> int res=num&mask;
>> printf("%d",res);
>> }
>> int main()
>> {
>> dosomething(56);
>> dosomething(64);
>> dosomething(127);
>> return 0;
>> }
>>
>> please explain  the logic behind the output.
>>
>> Thanks,
>> Rajesh
>>
>  --
>
>
>

-- 


Reply via email to