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

后端 未结 6 2109
孤街浪徒
孤街浪徒 2021-02-09 07:12

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条回答
  •  悲&欢浪女
    2021-02-09 07:56

    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.

提交回复
热议问题