Reported September 2024
Zscalerbit manipulation

Check Whether a Byte Is Nonzero

Reported by candidates from Zscaler's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Zscaler OA. Under 2s to a working solution.
Founder's read

Zscaler's September 2024 OA has a question that looks like a trick and is really one line of bit math. It hands you a nonnegative 64-bit value and a byte index, and asks if that byte is nonzero. If you've got an invite for the next few days, this is the kind of problem where a rushed candidate overthinks it with strings and hex conversion. It's a bit-manipulation problem. Shift, mask, compare. If your brain freezes on the operators, StealthCoder runs invisibly during the live OA and can hand you the answer as a safety net.

The problem

Given a nonnegative 64-bit integer value and a zero-based byte index byteIndex, return whether the selected byte is nonzero.
Byte index 0 is the least-significant byte. Each byte contains 8 bits.

Function
isByteNonzero(value: long, byteIndex: int) → boolean

Examples
Example 1
value = 305419896
byteIndex = 0
return = true
The least-significant byte is hexadecimal 78, which is nonzero.
Example 2
value = 16711680
byteIndex = 1
return = false
The value is hexadecimal 00FF0000; byte index 1 is 00.
Example 3
value = 0
byteIndex = 7
return = false
Every byte of zero is zero.

Constraints
0 <= value <= 2^63 - 1
0 <= byteIndex <= 7

Reported by candidates. Source: FastPrep

Pattern and pitfall

The whole problem reduces to extracting 8 bits. Shift the value right by byteIndex * 8 so the target byte lands in the lowest position. Then AND with 0xFF to isolate it. Return whether the result is not zero. That's O(1) time and space. The common pitfalls are small but costly. Shifting by byteIndex instead of byteIndex * 8 is the classic one. Forgetting the mask means you test all higher bytes too, which breaks Example 2, where byte 1 is 00 but byte 2 is FF. Also watch signedness. The constraints keep value nonnegative, so a signed right shift is safe, but use a long literal like 0xFFL so the mask isn't truncated to int. Check Example 3 mentally: zero shifted by 56 is zero, so false. If you blank on operator syntax during the live OA, StealthCoder is the hedge that gives you the line.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Check Whether a Byte Is Nonzero cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Zscaler's OA.

Zscaler reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Check Whether a Byte Is Nonzero FAQ

How hard is the Zscaler byte nonzero question really?+

Easy if you know bit operations, annoying if you don't. The logic is one expression. The difficulty is remembering shift and mask syntax under pressure, not the algorithm. Most of the risk is off-by-factor-of-8 mistakes in the shift amount.

What's the trick to solve it?+

Shift right by byteIndex * 8, AND with 0xFF, and check that the result isn't zero. That isolates exactly one byte. Don't convert to a string or hex, it works but it's slower and more error-prone.

What mistakes fail the examples?+

Skipping the mask fails Example 2, since higher bytes are nonzero while byte 1 is zero. Shifting by byteIndex instead of byteIndex * 8 fails most cases. Using an int mask on a long can also cause subtle bugs in other languages.

Is bit manipulation still asked in OAs like this?+

Yes, small bit-level questions keep showing up, and Zscaler reported this one in September 2024. They're short, so a single wrong constant sinks you. Expect masks, shifts, and parity checks rather than hard bit-DP.

How do I prepare in 48 hours?+

Write the shift-and-mask pattern from memory in your language. Test it on the three examples and on edge cases like value 0 and byteIndex 7. Also practice extracting a bit and a nibble so the operators feel automatic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Zscaler.

OA at Zscaler?
Invisible during screen share
Get it