一个弱问题?无符号类型关键字不是unsigned么?怎么编译通不过?

javahui 2003-08-18 09:26:33
byte的范围是-128到127,我要让它支持0-256,所以需要定义无符号型byte,难道不是unsigned byte吗?搞晕了,大家帮忙。
...全文
25 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
javahui 2003-08-18
  • 打赏
  • 举报
回复
谢谢了,我终于搞清楚了,结帖! 分少了点,我再加一点.
cbhyk 2003-08-18
  • 打赏
  • 举报
回复
InputStream:
public abstract int read()throws IOException
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
A subclass must provide an implementation of this method.

OutputStream:
public abstract void write(int b) throws IOException
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.
javahui 2003-08-18
  • 打赏
  • 举报
回复
不是节约,是有这个需要,通讯协议是这样规定的,一个字节可能传递的值就是大于127的,所以byte类型做不到.定义成short的就与通讯协议不一致了.
javahui 2003-08-18
  • 打赏
  • 举报
回复
那怎么办,0-256的数字不能定义为byte吗,非要定义成short的?
shine333 2003-08-18
  • 打赏
  • 举报
回复
没有,干吗要用byte作数字型的表示呢,
这年头不会为了节约几个字节用byte吧
scbb 2003-08-18
  • 打赏
  • 举报
回复
xixi,好像没有办法呀。
jmars 2003-08-18
  • 打赏
  • 举报
回复
java没有unsigned

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧