MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / SignAndMagnitudeToBiased

Method SignAndMagnitudeToBiased

tests/gtest/gtest.h:6800–6808  ·  view source on GitHub ↗

Converts an integer from the sign-and-magnitude representation to the biased representation. More precisely, let N be 2 to the power of (kBitCount - 1), an integer x is represented by the unsigned number x + N. For instance, -N + 1 (the most negative number representable using sign-and-magnitude) is represented by 1; 0 is represented by N; and N - 1 (the biggest number representable using

Source from the content-addressed store, hash-verified

6798 // Read http://en.wikipedia.org/wiki/Signed_number_representations
6799 // for more details on signed number representations.
6800 static Bits SignAndMagnitudeToBiased(const Bits &sam) {
6801 if (kSignBitMask & sam) {
6802 // sam represents a negative number.
6803 return ~sam + 1;
6804 } else {
6805 // sam represents a positive number.
6806 return kSignBitMask | sam;
6807 }
6808 }
6809
6810 // Given two numbers in the sign-and-magnitude representation,
6811 // returns the distance between them as an unsigned number.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected