What is the fastest way to get the 4 least significant bits in a byte (C++)?

后端 未结 6 1113
说谎
说谎 2021-02-09 07:00

I\'m talking about this:

If we have the letter \'A\' which is 77 in decimal and 4D in Hex. I am looking for the fastest way to get D.

I thought about two ways:

6条回答
  •  旧时难觅i
    2021-02-09 07:47

    It will depend on on the architecture to some extent - shifting up and back down on an ARM is probably the fastest way - however the compiler should do that for you. In fact, all of the suggested methods will probably be optimized to the same code by the compiler.

提交回复
热议问题