MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / HighestOneBitValue

Function HighestOneBitValue

Bcore/src/main/cpp/base/bit_utils.h:335–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333// Returns value with bit set in hightest one-bit position or 0 if 0. (java.lang.X.highestOneBit).
334template <typename T>
335inline static T HighestOneBitValue(T opnd) {
336 using unsigned_type = typename std::make_unsigned<T>::type;
337 T res;
338 if (opnd == 0) {
339 res = 0;
340 } else {
341 int bit_position = BitSizeOf<T>() - (CLZ(static_cast<unsigned_type>(opnd)) + 1);
342 res = static_cast<T>(UINT64_C(1) << bit_position);
343 }
344 return res;
345}
346
347// Rotate bits.
348template <typename T, bool left>

Callers

nothing calls this directly

Calls 1

CLZFunction · 0.85

Tested by

no test coverage detected