z********i 发帖数: 60 | 1 Using io.Outputstream, I need to write some 32 bit integer to the
stream. any value is fine except -2147483648 and 2147483648. I tried
to just mask 32 bits and cut them in bytes. The bitstream is just
ended with them without any warning.
Thank you for taking time. |
m******t 发帖数: 2416 | 2
Ever occurred to you 2147483648 is not a valid int?
【在 z********i 的大作中提到】 : Using io.Outputstream, I need to write some 32 bit integer to the : stream. any value is fine except -2147483648 and 2147483648. I tried : to just mask 32 bits and cut them in bytes. The bitstream is just : ended with them without any warning. : Thank you for taking time.
|
z********i 发帖数: 60 | 3
it is 0x80000000. do you think it is overflow?
【在 m******t 的大作中提到】 : : Ever occurred to you 2147483648 is not a valid int?
|
m******t 发帖数: 2416 | 4
JLS 4.2.1: "For int, from -2147483648 to 2147483647, inclusive".
【在 z********i 的大作中提到】 : : it is 0x80000000. do you think it is overflow?
|
z********i 发帖数: 60 | 5 but how can I write 255 for in a byte. Java has no unsigned int, unsigned
byte..right? Thanks
【在 m******t 的大作中提到】 : : JLS 4.2.1: "For int, from -2147483648 to 2147483647, inclusive".
|
m******t 发帖数: 2416 | 6
If you are the only one reading/writing this stream, just use
ObjectOutputStream.writeLong().
【在 z********i 的大作中提到】 : but how can I write 255 for in a byte. Java has no unsigned int, unsigned : byte..right? Thanks
|
z********i 发帖数: 60 | 7 Since I need to write a serial bits into a stream, I changed to use
DataOutputStream.writeChar(int v). for char, it is valid from 0 to 0xffff, for
my program, the value of 65277 (0xfefd) works fine, but 65278 cannot write
correctly. Any idea?
【在 m******t 的大作中提到】 : : If you are the only one reading/writing this stream, just use : ObjectOutputStream.writeLong().
|
m******t 发帖数: 2416 | 8
for
Not sure, maybe it has to do with unicode.
I'm still not sure I understand your requirement. Does this stream have to
conform to a certain standard? Is there any other code that will directly
access this stream? etc. These are all the questions need to be answered
before you can decide how you want to do this.
【在 z********i 的大作中提到】 : Since I need to write a serial bits into a stream, I changed to use : DataOutputStream.writeChar(int v). for char, it is valid from 0 to 0xffff, for : my program, the value of 65277 (0xfefd) works fine, but 65278 cannot write : correctly. Any idea?
|