1

Most bitshift solutions I have seen for converting an int to a byte array go like this:

return new byte [] {
    (byte) ((i >> 24) & 0xFF),
    (byte) ((i >> 16) & 0xFF),
    (byte) ((i >> 8) & 0xFF),
    (byte) (i & 0xFF);
}

Why the & 0xFF??

Ancat Dubher
  • 101
  • 5

1 Answers1

0

& 0xFF is redundant and makes no difference in the given case

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275