Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

JAVA and byte arrays

I'm trying to use an API where there's a socket is used to communicate. A request is made up of different parts and one of them is the header which is stated as so:

Fixed header: 2 bytes, fixed at 0xffff

Generally I'm not good with bytes and streams, since I've never used it. So how should i create said byte array? I've tried the following

byte[] header = new byte[]{(byte)0xff, (byte)0xff};

But they bytes each become -1, which I believe is because 0xFF translates to 255 which is outside of the signed byte range (-128 to +127), but then how do I create a header like that?

Answer*

Draft saved
Draft discarded
Cancel

lang-java

AltStyle によって変換されたページ (->オリジナル) /