FastPrepExtract a Register Bit Field
Problems/Extract a Register Bit Field

Extract a Register Bit Field

Apple logoApple● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple new grad onsite interview. The report names register bit extraction. Our version is about 65% the same as the reported question. We chose these: an unsigned 32-bit register, fields made of neighboring bits, counting bits from the least significant one, and the rules for a valid offset and width.

An unsigned 32-bit register contains the integer value. Number the bits starting at zero from the rightmost, lowest-value bit.

Extract the width consecutive bits beginning at offset, shift that field down so its lowest bit becomes bit zero, and return its unsigned numeric value. Do not change the register value.

Function

extractRegisterBits(value: long, offset: int, width: int) → long

Examples

Example 1

value = 42offset = 1width = 3return = 5

In binary, value is 101010. The field starts at the offset, so shift right once to drop the lowest bit. The width is three, so keep the lowest three bits of what is left: 101. That is five, so the answer is five.

Example 2

value = 4294967295offset = 0width = 32return = 4294967295

The offset is zero and the width covers the whole register. All thirty-two bits are ones, and the field keeps every one of them. So the answer is the same as value.

Constraints

  • 0 <= value <= 4294967295.
  • 0 <= offset <= 31.
  • 1 <= width <= 32 and offset + width <= 32.
  • value and the answer use a signed 64-bit type, so the whole unsigned 32-bit range fits.

More Apple Onsite Interview questions

  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • FIFO Mutex Operation TraceONSITE INTERVIEW · Seen Oct 2026
  • Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Parse Nested HTML into a TreeONSITE INTERVIEW · Seen Oct 2026
  • Thread-Safe Concurrent Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Palindrome Match PercentageONSITE INTERVIEW · Seen Sep 2026
  • Binary Tree Nodes at Distance KONSITE INTERVIEW · Seen Aug 2026
  • BST to Sorted Circular Doubly Linked ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
  • Missing and Repeated NumberCommvault · ONSITE INTERVIEWCommvault interview questions
  • Check Endianness Of A Byte ArrayNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Swap Two Integers Without a Temporary VariableOracle · ONSITE INTERVIEWOracle interview questions
  • Swap Two Numbers Without a Third VariableInfosys · ONSITE INTERVIEWInfosys 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

Interview reports that mention this question

  • Apple New Grad SWE Interviews: 37 Experiences (Part 1 of 3)

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public long extractRegisterBits(long value, int offset, int width) {
        // Write your solution here.
    }

}
Checking account…