General Question

gorillapaws's avatar

C++/Arduino programmers, can you help me understand this line of code?

Asked by gorillapaws (30520points) September 22nd, 2020
1 response
“Great Question” (1points)

I’m just starting to dip my little toe into arduinos and maybe some hobbyist robotics. I was looking at the driver for an Arduino device and I came across the following line:

#define RPLIDAR_RESP_MEASUREMENT_SYNCBIT (0×1<<0)

then there’s:

#define RPLIDAR_RESP_MEASUREMENT_CHECKBIT (0×1<<0)

If you’re doing a left bit-shift by a value of 0, what’s the point? why not just define it as “0×1”? This is a driver, so they’re defining the response from the device. It just seems very counter intuitive. I suspect that there is an important concept underlying that code that I don’t understand and since I’m not sure what that is, I’m not sure what keywords I should be searching to figure it out.

Any help would be greatly appreciated.

Topics: , , , ,
Observing members: 0
Composing members: 0

Answers

Zaku's avatar

It’s for consistency and code readability, to communicate intent and patterns clearly.

Other #defines undoubtedly bit-shift by values other than zero, so this clarifies what the intent is.

Except when someone thinks the way you’ve been thinking about it. ;-)

Answer this question

Login

or

Join

to answer.

Mobile | Desktop


Send Feedback   

`