what is 0x3<<14 mean ?

Apr 18, 2022 at 6:03am
I am new in c++ coding in this chapter I can not understand the meaning of " mask = 0x4<<16;"
Last edited on Apr 25, 2022 at 12:04pm
Apr 18, 2022 at 7:02am
Apr 18, 2022 at 7:57am
Integer literals starting with 0x is hexadecimal (base 16).
Integer literals starting with just 0 is octal (base 8).
Integer literals starting with any non-zero digit 1-9 is decimal (base 10).

https://onlinetoolz.net/bitshift#base=16&value=3&bits=32&steps=14&dir=l&type=ari&allsteps=1
Last edited on Apr 18, 2022 at 9:27am
Apr 18, 2022 at 9:01am
<< in this context means left shift. So 0x3 << 14 means 3 left shift by 14 or in binary 0011 left shift by 14 which gives

1100000000000000 in binary which is 0xc000

>> in this context means right shift.

Note that when working with shift, it's better to work in unsigned values - otherwise you can get issues with sign extension.
Last edited on Apr 18, 2022 at 9:03am
Apr 18, 2022 at 10:25am
this is, by the way, horrible code.
the function uses pointers to replace references (pass by reference) and constant integers are formed with convoluted and undocumented math for no apparent reason.
Likely the hardware manual for this system can demystify some of the why & what here, but even so, it could stand a few comments.
Topic archived. No new replies allowed.