ByteByteGo logo
menuProblems List

Swap Odd and Even Bits

Medium

Given an unsigned 32-bit integer n, return an integer where all of n's even bits are swapped with their adjacent odd bits.

Example 1:

Input: n = 41
Output: 22

Example 2:

Input: n = 23
Output: 43

You can practice coding exercises online by logging into bytebytego.com on your laptop.