Android 進位互相轉換

來源:互聯網
上載者:User

標籤:ring   byte   二進位   too   方法   hex   進位轉換   字元   聲明   

byte轉換為16進位

public static String GetByte2Str(byte b) {

byte[] buff = new byte[2];

 buff[0] = mHex[(b >> 4) & 0x0f];

buff[1] = mHex[b & 0x0f];

return new String(buff);

}

private static final byte[] mHex = "0123456789ABCDEF".getBytes();

16進位轉換為10進位

int integerState = Integer.valueOf(GetByte2Str(mAcState), 16);

10進位轉換為2進位串

String s=Integer.toBinaryString(integerState); //二進位串

2進位的字串轉換為10進位

String aa = "1010";
Integer f = Integer.parseInt(aa,2);

 

 

Java中在聲明數字時預設採用的是十進位,可以在數字前加上符號表示數字採用八進位【前面加0(零)】或者十六進位【前面加上0x(零x)】。

 Java的整型封裝類Integer和Long提供toString(int i,int radix)靜態方法,可以將一個任意進位的整數轉換為其他進位的整數。

 使用Integer或Long的toBinaryString方法將整數轉換為二進位。

使用Integer或Long的toOctalString方法將整數轉換為八進位。

使用Integer或Long的toHexString方法將整數轉換為十六進位。

使用Integer或Long的toString(int i)方法可以將其他進位的整數轉換為十進位的整數的字串表示。

 

Android 進位互相轉換

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.