FastPrepCheck Whether a Byte Is Nonzero

Check Whether a Byte Is Nonzero

Zscaler logoZscaler● EasyINTERNONSITE INTERVIEW
Learn

Problem statement

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 = 305419896byteIndex = 0return = true

The least-significant byte is hexadecimal 78, which is nonzero.

Example 2

value = 16711680byteIndex = 1return = false

The value is hexadecimal 00FF0000; byte index 1 is 00.

Example 3

value = 0byteIndex = 7return = false

Every byte of zero is zero.

Constraints

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

More Zscaler problems

See Zscaler hiring insights
public boolean isByteNonzero(long value, int byteIndex) {
  // write your code here
}
value305419896
byteIndex0
expectedtrue
Checking account…