FastPrepSwap Adjacent Nibbles

Swap Adjacent Nibbles

Arista Networks logoArista Networks● EasyFULLTIMEPHONE SCREEN
Learn

Problem 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) → long

Examples

Example 1

value = 305419896return = 558065031

The hexadecimal digits 12 34 56 78 become 21 43 65 87.

Constraints

  • 0 <= value <= 2^32 - 1

More Arista Networks problems

See Arista Networks hiring insights
public long swapAdjacentNibbles(long value) {
    // Write your solution here.
}
value305419896
expected558065031
Checking account…