[英]Java convert unsigned big integer to unsigned byte
值較高時,如何將無符號BigInteger轉換為無符號字節?
String value = "202";
BigInteger a = new BigInteger( value );
Byte b = new BigInteger( value ).byteValue() // returns -54
如何從BigInteger獲取無符號字節值?
您應該將“ 202” int
為int
因為java沒有unsigned byte
。 我想.intValue()
會有所幫助
也許您正在尋找這樣的東西:
import java.math.*;
public class MyClass {
public static void main(String args[]) {
String value = "202";
BigInteger a = new BigInteger( value );
Byte b = new BigInteger( value ).byteValue() ;
System.out.println(a);
System.out.println(unsignedToBytes((byte)b));
}
public static int unsignedToBytes(byte b) {
return (int)b & 0xFF;
}
}
這是一個很好的解釋: 我們可以在Java中制作無符號字節嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.