❶ java怎麼把16進制的數轉換為10進制的
使用java.math.BigInteger
構造函數BigInteger(String val, int radix) :          將指定基數的 BigInteger 的字元串表示形式轉專換為 BigInteger。
new BigInteger("", 16).toString()即可屬
❷ java中如何把十六進制轉為十進制
分類:  電腦/網路 >> 程序設計 >> 其他編程伍亮語言 
   問題描述: 
  
 我用的java1.4 請問如何將十六進制整形數轉化為十進制數橘沖的
 
   解析: 
  
 import java.awt.*; 
 
 public class d2x extends Frame 
 
 {
int decimalValue= 0; 
 
 String baseXValue = new String("0"); 
 
 TextField dDisplay,xDisplay; 
 
 d2x constructor 
 
 d2x() 
 
 {
 
 super("Decimal Converter");set the title of the frame 
 
 MenuBar mb = new MenuBar();
 
 Button d2Binary = new Button("Binary"); 
 
 Button d2Octal = new Button("Octal"); 
 
 Button d2Hex = new Button("Hex"); 
 
 Button d2Base36 = new Button("Base36"); 
 
 Panel p1 = new Panel(); 
 
 Panel p2 = new Panel(); 
 
 Panel p3 = new Panel(); 
 
 add a simple menu 
 
 Menu m = new Menu("Application"); 
 
 m.add(new CheckboxMenuItem("Base 36 Active")); 
 
 m.add(new MenuItem("Exit")); 
 
 add menu to menubar 
 
 mb.add(m); 
 
 setMenuBar(mb);install this menu bar in the frame 
 
 Add buttons to their own panel 
 
 p3.setLayout(new FlowLayout()); 
 
 p3.add(d2Binary); 
 
 p3.add(d2Octal); 
 
 p3.add(d2Hex); 
 
 p3.add(d2Base36); 
 
 Add text fields 
 
 Label dLabel = new Label("Enter Deecimal: "); 
 
 Label xLabel = new Label("Converted Value: "); 
 
 dDisplay = new TextField(Integer.toString(decimalValue),7); 
 
 xDisplay = new TextField(baseXValue,32); 
 
 xDisplay.setEditable(false); 
 
 p1.setLayout(new FlowLayout(FlowLayout.LEFT)); 
 
 p2.setLayout(new FlowLayout(FlowLayout.LEFT)); 
 
 p1.add(dLabel); 
 
 p1.add(dDisplay); 
 
 p2.add(xLabel); 
 
 p2.add(xDisplay); 
 
 Add the panels 
 
 add("North",p1); 
 
 add("Center",p2); 
 
 add("South"薯殲,p3); 
 
 }end d2x constructor 
 
 public void start() 
 
 { 
 
 resize(400,150); 
 
 show(); 
 
 }
 
 public void updateXDisplay() 
 
 { 
 
 xDisplay.setText(baseXValue); 
 
 }
 
 public boolean handleEvent(Event evt) 
 
 { 
 
 if (evt.target instanceof MenuItem) 
 
 { 
 
 if ("Exit".equals(((MenuItem)evt.target).getLabel())) 
 
 { 
 
 hide(); 
 
 dispose(); 
 
 System.exit(0); 
 
 return false; 
 
 } 
 
 return true; 
 
 } 
 
 else if(evt.target instanceof Button) 
 
 { 
 
 String whick = ((Button)evt.target).getLabel(); 
 
 if (whick.equals("Binary")) 
 
 { 
 
 decimalValue = Integer.parseInt(dDisplay.getText());
 
 baseXValue = Integer.toString(decimalValue,2); 
 
 } 
 
 if (whick.equals("Octal")) 
 
 { 
 
 decimalValue = Integer.parseInt(dDisplay.getText()); 
 
 baseXValue = Integer.toString(decimalValue,8); 
 
 } 
 
 if (whick.equals("Hex")) 
 
 { 
 
 decimalValue = Integer.parseInt(dDisplay.getText()); 
 
 baseXValue = Integer.toString(decimalValue,16); 
 
 } 
 
 if (whick.equals("36")) 
 
 { 
 
 decimalValue = Integer.parseInt(dDisplay.getText()); 
 
 baseXValue = Integer.toString(decimalValue,36); 
 
 } 
 
 updateXDisplay(); 
 
 return true; 
 
 } 
 
 return false; 
 
 } 
 
 public static void main(String args[]) 
 
 { 
 
 d2x m = new d2x(); 
 
 m.start(); 
 
 }
 
 }
❸ JAVA 十六進制轉十進制
你的程序在i>256時,one變成一位十六進制數了,前面缺了一個0.
在i>256時,在one前面補一個0,就行了.
完整的程序如下:(改動的地方見注釋)
publicclassA{
publicstaticvoidmain(String[]args){
for(inti=1;i<260;i++){
byte[]cs=newbyte[2];
cs[0]=(byte)(i&0xFF);
cs[1]=(byte)((i/256)&0xFF);
System.out.println("cs[0]---"+cs[0]);
System.out.println("cs[1]---"+cs[1]);
Stringone=Integer.toHexString(cs[0]&0xFF);
Stringtwo=Integer.toHexString(cs[1]&0xFF);
System.out.println("one---"+one);
System.out.println("two---"+two);
if(one.length()==1)one="0"+one;//這里加一句
Stringthr=two+one;
System.out.println(thr);
inthh=Integer.valueOf(thr,16);
System.out.println("發出的數是:"+i);
System.out.println("返回的數是:"+hh);
}
}
}
❹ java怎麼把16進制的字元串轉化為十進制
toHexString 
public static String toHexString(int 
i)以十六進制的無符號整數形式返回一個整數參數的字元串表示形式。 
如果參數為負,那麼無符號整數值為參數加上 
232;否則等於該參數。將該值轉換為十六進制(基數 16)的無前導 0 的 ASCII 數字字元串。如果無符號數的大小值為零,則用一個零字元 '0' 
('\u0030') 表示它;否則,無符號數大小的表示形式中的第一個字元將不是零字元。用以下字元作為十六進制數字: 
0123456789abcdef 
這些字元的范圍是從 '\u0030' 到 '\u0039' 和從 '\u0061' 到 '\u0066'。如果希望得到大寫字母,可以在結果上調用 
String.toUpperCase() 方法: 
Integer.toHexString(n).toUpperCase() 
參數: 
i 
- 要轉換成字元串的整數。 
返回: 
用十六進制(基數 16)參數表示的無符號整數值的字元串表示形式。 
// 轉化字元串為十六進制編碼 
public static String toHexString(String s) 
{ 
String str=""; 
for 
(int i=0;i<s.length();i++) 
{ 
int ch = (int)s.charAt(i); 
String s4 
= Integer.toHexString(ch); 
str = str + s4; 
} 
return str; 
} 
// 轉化十六進制編碼為字元串 
public static String toStringHex(String s) 
{ 
byte[] baKeyword = new byte[s.length()/2]; 
for(int i = 0; i < 
baKeyword.length; i++) 
{ 
try 
{ 
baKeyword[i] = (byte)(0xff & 
Integer.parseInt(s.substring(i*2, i*2+2),16)); 
} 
catch(Exception e) 
{ 
e.printStackTrace(); 
} 
} 
try 
{ 
s = new 
String(baKeyword, "utf-8");//UTF-16le:Not 
} 
catch (Exception e1) 
{
❺ JAVA編程:將輸入的16進制數字串轉為10進制數並輸出。
在main方法中直接調用即可,代碼如下:
publicstaticvoidmain(String[]args){
HexToDec("1e6f");
}
/**
*將十六進制的字元串轉化為十進制的數值
*/
publicstaticlongHexToDec(StringhexStr){
Map<String,Integer>hexMap=prepareDate();//先准備對應關系數據
intlength=hexStr.length();
longresult=0L;//保存最終的結果
for(inti=0;i<length;i++){
result+=hexMap.get(hexStr.subSequence(i,i+1))*Math.pow(16,length-1-i);
}
System.out.println("hexStr="+hexStr+",result="+result);
returnresult;
}
/**
*准備十六進制字元對應關系。如("1",1)...("A",10),("B",11)
畝毀嫌*/
privatestaticHashMap<String,Integer>prepareDate(){
HashMap<String,Integer>hashMap=newHashMap<String,Integer>();
for(inti=1;余寬i<=9;i++){
hashMap.put(i+"",i);
}
hashMap.put("a",10);
hashMap.put("迅手b",11);
hashMap.put("c",12);
hashMap.put("d",13);
hashMap.put("e",14);
hashMap.put("f",15);
returnhashMap;
}
❻ 如何用java將一個16進制的數轉為單位元組的10進制數
十六進制轉十進制最簡單的方法
System.out.println(Integer.valueOf(0x10,16));
16
擴棗拍叢展
十進制轉二進制凳櫻、八進制、十六賀歷進制
System.out.println("10的二進制="+Integer.toBinaryString(10));
System.out.println("10的八進制="+Integer.toOctalString(10));
System.out.println("10的十六進制="+Integer.toHexString(10));
10的二進制=1010
10的八進制=12
10的十六進制=a
❼ 如何將十六進制轉成十進制,在java中
intn16=0x10;
intn10=16;
滾猜槐//十進制轉化為十六進制
Strings16=Integer.toHexString(n10);
//十六進制轉化為十進制
inta10=Integer.parseInt(s16,16);
兆褲//實際上十六進制是可以直接當十進制使用的,注意賦值時類型選擇,防止精度丟失
System.out.println(n16);
System.out.println(n10);
System.out.println(s16);
大友System.out.println(a10);
❽ java十六進制怎麼轉化成十進制
public class Hex {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // 十進制轉化為十六進制
        int data = 15;
        String Hex = Integer.toHexString(data);
        System.out.println(Hex);
        // 十橡缺盯六進梁和制扮胡轉化為十進制
        System.out.println(Integer.parseInt(Hex,16));
    }
}
❾ 使用java,如何將十六進制數D6CD2F01轉換為十進制數19910102
import java.util.Scanner;
public class test2{
public static void main(String [] args){
Scanner cin=new Scanner(System.in);
String num1="D6CD2F01";//"D6CD2F01";
//long n=Long.parseLong(num1,16);//由16進制轉化為10進制(兩個都行,1:返回long;2:返回Long)
long n=Long.valueOf(num1,16);
System.out.print(n);
/*
D6CD2F01的十進制數已經超過int的范圍了
3603771137
*/
}
}

❿ Java十六進制轉換為十進制
import java.util.Scanner;
public class Test60025 {
  public static void main(String []args){
         int repeat, i;
         String s;
         System.out.print("輸入Repeat的值:");
         Scanner in=new Scanner(System.in);
         repeat=in.nextInt();
         in.nextLine();
         int arr[]=new int[repeat];
         for(i=0; i<repeat; i++){
          System.out.print("輸入任意字元:");
          s=in.nextLine();
          arr[i]=Integer.valueOf(captureHex(s), 16);
         }
         System.out.println("輸出:");
         for (int j = 0; j < arr.length; j++) {
    System.out.println(arr[j]);
   }
   
    }
  
  public static String captureHex(String target){//獲取字元串中十六進制的字元,A與a為同一字元
   char ch=0;
   String validStr="";
   for (int i = 0; i < target.length(); i++) {
    ch=target.charAt(i);
    if((ch>='0'&&ch<='9')||(ch>='a'&&ch<='f')||(ch>='A'&&ch<='F')){
     validStr+=ch;
    }
  }
   if("".equals(validStr)){
    System.out.println("非法輸入,此行不含任何十六進制字元");
    validStr="0";
   }
   return validStr;
  }
}