FastPrepSwap Adjacent Bits in a 32-Bit Word
Problems/Swap Adjacent Bits in a 32-Bit Word

Swap Adjacent Bits in a 32-Bit Word

NVIDIA logoNVIDIA● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The NVIDIA autonomous-vehicle MLE onsite report, for a full-time role, asks to swap every pair of bits and gives 1001 → 0110. It does not say the width of a machine word, whether it is signed, or the interface. Here we use a 32-bit unsigned word, held in a nonnegative 64-bit integer. These are our own rules.

Our version is about 90% the same as the reported question.

Given a nonnegative integer value representing an unsigned 32-bit word, swap bits in every adjacent pair: positions 0 and 1, positions 2 and 3, and so on through positions 30 and 31. Position 0 is the least significant bit.

Return the resulting 32-bit word as a nonnegative integer. Leading zero bits are part of the word. For example, binary 1001 becomes 0110, so 9 becomes 6.

Function

swapAdjacentBits(value: long) → long

Examples

Example 1

value = 9return = 6

Low-order binary 1001 becomes 0110, which is 6.

Example 2

value = 1return = 2

The only set bit moves from position 0 to position 1.

Example 3

value = 2147483649return = 1073741826

The highest and lowest set bits move to positions 30 and 1.

Constraints

  • 0 <= value <= 4294967295.
  • Interpret value as exactly 32 unsigned bits. The input and output use a signed 64-bit integer type so every 32-bit result remains nonnegative.

More NVIDIA Onsite Interview questions

  • Check Endianness Of A Byte ArrayONSITE INTERVIEW · Seen Sep 2026
  • Implement MallocONSITE INTERVIEW · Seen Sep 2026
  • Implement PrintfONSITE INTERVIEW · Seen Sep 2026
  • Merge Two Arrays Into Sorted OrderONSITE INTERVIEW · Seen Sep 2026
  • Middle Node Of A Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Ping Reply TrackingONSITE INTERVIEW · Seen Sep 2026
  • Reverse A StringONSITE INTERVIEW · Seen Sep 2026
  • Maximum Fish in a GridONSITE INTERVIEW · Seen Sep 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • First Register Overflow TickONSITE INTERVIEW · Seen May 2024

Similar questions at other companies

  • Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
  • Missing and Repeated NumberCommvault · ONSITE INTERVIEWCommvault interview questions
  • Swap Two Integers Without a Temporary VariableOracle · ONSITE INTERVIEWOracle interview questions
  • Swap Two Numbers Without a Third VariableInfosys · ONSITE INTERVIEWInfosys interview questions
  • Extract a Register Bit FieldApple · ONSITE INTERVIEWApple interview questions
  • Add Two Binary StringsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Add BinaryMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Count Set Bits in an Integer ArrayAkuna Capital · ONSITE INTERVIEWAkuna Capital interview questions
  • Check Whether a Byte Is NonzeroZscaler · ONSITE INTERVIEWZscaler interview questions
  • Find the Odd-Occurrence ValueExpedia · ONSITE INTERVIEWExpedia interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public long swapAdjacentBits(long value) {
        // Write your code here.
    }
}
Checking account…