mirror of
https://github.com/fraillt/bitsery.git
synced 2026-10-03 15:35:23 +00:00
integer casts part3
This commit is contained in:
committed by
Mindaugas Vinkelis
parent
9cade41dbb
commit
16f637da0d
@@ -43,11 +43,11 @@ TValue getValue(bool isPositive, size_t significantBits) {
|
||||
|
||||
using TUnsigned = typename std::make_unsigned<TValue>::type;
|
||||
TUnsigned mask = {};
|
||||
mask = ~mask; // invert shiftByBits
|
||||
mask = static_cast<TUnsigned>(~mask); // invert shiftByBits
|
||||
auto shiftBy = bitsery::details::BitsSize<TValue>::value - significantBits;
|
||||
mask >>= shiftBy;
|
||||
mask = static_cast<TUnsigned>(mask >> shiftBy);
|
||||
//cast to unsigned when applying mask
|
||||
return (TUnsigned)v ^ mask;
|
||||
return static_cast<TValue>(v ^ mask);
|
||||
}
|
||||
|
||||
// helper function, that serialize and return deserialized value
|
||||
|
||||
Reference in New Issue
Block a user