[LinuxBIOS] Another dumb C question

Corey Osgood corey.osgood at gmail.com
Thu Jul 12 12:08:04 CEST 2007


Joseph Smith wrote:
> Quoting Peter Stuge <peter at stuge.se>:
>
>   
>>> value = 9
>>>
>>> (2 << (value - 1))
>>>
>>>       
>
>   
>> Bit shift is fine methinks but I would suggest:
>>
>> (1 << value)
>>
>> instead of
>>
>> (2 << (value - 1))
>>
>>
>> //Peter
>>
>>     
> Not sure I understand. I am trying to get 2 "to the power of" value.
>
> if value = 9
> (1 << value)
> This equals 18???? Not 2^9 = 512
> where
> (2 << (value - 1))
> (2 << (9 - 1))
> 2 << 8 = 512
>
> Thanks - Joe
>
>   
remember that 2 = (1 << 1). so 2 << (value - 1) = 1 << value. I'm not
sure where you're getting an 18 from, that makes no sense at all (since
18 in either hex or dec has two non-zero bits, so it's impossible to get
that result with just that binary shift).

-Corey




More information about the coreboot mailing list