Redian新闻
>
help about bitstream writer
avatar
help about bitstream writer# Java - 爪哇娇娃
z*i
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.
avatar
m*t
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.

avatar
z*i
3

it is 0x80000000. do you think it is overflow?

【在 m******t 的大作中提到】
:
: Ever occurred to you 2147483648 is not a valid int?

avatar
m*t
4

JLS 4.2.1: "For int, from -2147483648 to 2147483647, inclusive".

【在 z********i 的大作中提到】
:
: it is 0x80000000. do you think it is overflow?

avatar
z*i
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".

avatar
m*t
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

avatar
z*i
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().

avatar
m*t
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?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。