Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

convert left shifted LSB bits to 1

I need to convert LSB 0 to 1 in left shift:

x=5;
int num = 0x02;//0b00000010
shiftVal = num << x;// 0b01000000

shiftVal should convert to 0b01011111

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Simply set them to 1 using the or operator. To get all one bits just do (1 << x) - 1

hiftVal = (num << x) | ((1 << x) - 1);

See also

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading