国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
java 進(jìn)制轉(zhuǎn)換
由于Unicode兼容ASCII(0~255),因此,上面得到的Unicode就是ASCII。
至于轉(zhuǎn)換成二進(jìn)制或其他進(jìn)制,Java API提供了方便函數(shù),你可以查Java的API手冊(cè)。
以字符a的ASCII為例:
Java代碼
  1. int i = 'a';   
  2. String iBin = Integer.toBinaryString(i);//二進(jìn)制   
  3. String iHex = Integer.toHexString(i);//十六進(jìn)制   
  4. String iOct = Integer.toOctalString(i);//八進(jìn)制   
  5. String iWoKao = Integer.toString(i,3);//三進(jìn)制或任何你想要的35進(jìn)制以下的進(jìn)制  

DEC

[集]java中進(jìn)行二進(jìn)制,八進(jìn)制,十六進(jìn)制,十進(jìn)制間進(jìn)行相互轉(zhuǎn)換     
十進(jìn)制轉(zhuǎn)成十六進(jìn)制:
Integer.toHexString(int i)
十進(jìn)制轉(zhuǎn)成八進(jìn)制
Integer.toOctalString(int i)
十進(jìn)制轉(zhuǎn)成二進(jìn)制
Integer.toBinaryString(int i)
十六進(jìn)制轉(zhuǎn)成十進(jìn)制
Integer.valueOf("FFFF",16).toString()
八進(jìn)制轉(zhuǎn)成十進(jìn)制
Integer.valueOf("876",8).toString()
二進(jìn)制轉(zhuǎn)十進(jìn)制
Integer.valueOf("0101",2).toString()

有什么方法可以直接將2,8,16進(jìn)制直接轉(zhuǎn)換為10進(jìn)制的嗎?
java.lang.Integer類
parseInt(String s, int radix)
使用第二個(gè)參數(shù)指定的基數(shù),將字符串參數(shù)解析為有符號(hào)的整數(shù)。
examples from jdk:
parseInt("0", 10) returns 0
parseInt("473", 10) returns 473
parseInt("-0", 10) returns 0
parseInt("-FF", 16) returns -255
parseInt("1100110", 2) returns 102
parseInt("2147483647", 10) returns 2147483647
parseInt("-2147483648", 10) returns -2147483648
parseInt("2147483648", 10) throws a NumberFormatException
parseInt("99",
throws a NumberFormatException
parseInt("Kona", 10) throws a NumberFormatException
parseInt("Kona", 27) returns 411787

進(jìn)制轉(zhuǎn)換如何寫(二,八,十六)不用算法
Integer.toBinaryString
Integer.toOctalString
Integer.toHexString

例一:
Java代碼
  1.   
  2. public class Test{   
  3. public static void main(String args[]){   
  4.   
  5.    int i=100;   
  6.    String binStr=Integer.toBinaryString(i);   
  7.    String otcStr=Integer.toOctalString(i);   
  8.    String hexStr=Integer.toHexString(i);   
  9.    System.out.println(binStr);  


例二:
Java代碼
  1.   
  2. public class TestStringFormat {   
  3. public static void main(String[] args) {   
  4.    if (args.length == 0) {   
  5.       System.out.println("usage: java TestStringFormat <a number>");   
  6.       System.exit(0);   
  7.    }   
  8.   
  9.    Integer factor = Integer.valueOf(args[0]);   
  10.   
  11.    String s;   
  12.   
  13.    s = String.format("%d", factor);   
  14.    System.out.println(s);   
  15.    s = String.format("%x", factor);   
  16.    System.out.println(s);   
  17.    s = String.format("%o", factor);   
  18.    System.out.println(s);   
  19. }   
  20. }  

各種數(shù)字類型轉(zhuǎn)換成字符串型:

String s = String.valueOf( value); // 其中 value 為任意一種數(shù)字類型。

字符串型轉(zhuǎn)換成各種數(shù)字類型:
 
Java代碼
  1.   
  2. String s = "169";   
  3. byte b = Byte.parseByte( s );   
  4. short t = Short.parseShort( s );   
  5. int i = Integer.parseInt( s );   
  6. long l = Long.parseLong( s );   
  7. Float f = Float.parseFloat( s );   
  8. Double d = Double.parseDouble( s );  

數(shù)字類型與數(shù)字類對(duì)象之間的轉(zhuǎn)換:

 
Java代碼
  1. byte b = 169;   
  2. Byte bo = new Byte( b );   
  3. b = bo.byteValue();   
  4.   
  5. short t = 169;   
  6. Short to = new Short( t );   
  7. t = to.shortValue();   
  8.   
  9. int i = 169;   
  10. b = bo.byteValue();   
  11.   
  12. short t = 169;   
  13. Short to = new Short( t );   
  14. t = to.shortValue();   
  15.   
  16. int i = 169;   
  17. Integer io = new Integer( i );   
  18. i = io.intValue();   
  19.   
  20. long l = 169;   
  21. Long lo = new Long( l );   
  22. l = lo.longValue();   
  23.   
  24. float f = 169f;   
  25. Float fo = new Float( f );   
  26. f = fo.floatValue();   
  27.   
  28. double d = 169f;   
  29. Double dObj = new Double( d );   
  30. d = dObj.doubleValue();  
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
常用的基本進(jìn)制轉(zhuǎn)換
java基本數(shù)據(jù)類型轉(zhuǎn)換
RMI分布式
Java 異常的捕獲與處理詳解(一)
lambda表達(dá)式Stream流使用
java正確例題
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服