Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shift left with 1's behind? C language

Tags:

c

binary

shift

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.

like image 898
DRS Avatar asked Dec 31 '25 12:12

DRS


1 Answers

int output = (input << shift) | ((1 << shift) - 1);
like image 197
deGoot Avatar answered Jan 03 '26 04:01

deGoot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!