Problem · Bit Manipulation
Swap Adjacent Nibbles
Learn this problemProblem statement
Treat a non-negative value as exactly eight hexadecimal digits, including leading zeroes. Swap each adjacent pair of four-bit nibbles: the first with the second, the third with the fourth, and so on. Return the resulting unsigned 32-bit value as a long.
Function
swapAdjacentNibbles(value: long) → longExamples
Example 1
value = 305419896return = 558065031The hexadecimal digits 12 34 56 78 become 21 43 65 87.
Constraints
0 <= value <= 2^32 - 1