日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

无符号 byte java_我们能用Java做无符号字节吗?

發布時間:2025/3/21 java 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 无符号 byte java_我们能用Java做无符号字节吗? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原語是用Java簽名的,這與它們在內存/傳輸中的表示方式無關-字節僅為8位,是否將其解釋為有符號范圍取決于您。沒有魔法標志可以說“這是簽名的”或“這是未簽名的”。

在對原語進行簽名時,Java編譯器將阻止您將大于+127的值分配給一個字節(或低于-128)。但是,沒有什么可以阻止您為了實現這一點而降低int(或Short):int?i?=?200;?//?0000?0000?0000?0000?0000?0000?1100?1000?(200)byte?b?=?(byte)?200;

//?1100?1000?(-56?by?Java?specification,?200?by?convention)/*

*?Will?print?a?negative?int?-56?because?upcasting?byte?to?int?does

*?so?called?"sign?extension"?which?yields?those?bits:

*?1111?1111?1111?1111?1111?1111?1100?1000?(-56)

*

*?But?you?could?still?choose?to?interpret?this?as?+200.

*/System.out.println(b);?//?"-56"/*

*?Will?print?a?positive?int?200?because?bitwise?AND?with?0xFF?will

*?zero?all?the?24?most?significant?bits?that:

*?a)?were?added?during?upcasting?to?int?which?took?place?silently

*????just?before?evaluating?the?bitwise?AND?operator.

*????So?the?`b?&?0xFF`?is?equivalent?with?`((int)?b)?&?0xFF`.

*?b)?were?set?to?1s?because?of?"sign?extension"?during?the?upcasting

*

*?1111?1111?1111?1111?1111?1111?1100?1000?(the?int)

*?&

*?0000?0000?0000?0000?0000?0000?1111?1111?(the?0xFF)

*?=======================================

*?0000?0000?0000?0000?0000?0000?1100?1000?(200)

*/System.out.println(b?&?0xFF);?//?"200"/*

*?You?would?typically?do?this?*within*?the?method?that?expected?an

*?unsigned?byte?and?the?advantage?is?you?apply?`0xFF`?only?once

*?and?than?you?use?the?`unsignedByte`?variable?in?all?your?bitwise

*?operations.

*

*?You?could?use?any?integer?type?longer?than?`byte`?for?the?`unsignedByte`?variable,

*?i.e.?`short`,?`int`,?`long`?and?even?`char`,?but?during?bitwise?operations

*?it?would?get?casted?to?`int`?anyway.

*/void?printUnsignedByte(byte?b)?{

int?unsignedByte?=?b?&?0xFF;

System.out.println(unsignedByte);?//?"200"}

總結

以上是生活随笔為你收集整理的无符号 byte java_我们能用Java做无符号字节吗?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。