简体   繁体   中英

shift left with 1's behind? C language

i would like to know if this is possible...

I know that 255 = 11111111 and if i do 255 << pos*8 with pos=1 i will have 1111111100000000.

I would like to know if is possible to get the value 1111111111111111 with shift left without doing a cicle while or for.

Thanks.

int output = (input << shift) | ((1 << shift) - 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM