what is 0x3<<14 mean ?

I am new in c++ coding in this chapter I can not understand the meaning of " mask = 0x4<<16;"
Last edited on
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).

Last edited on
<< 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
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.