Excel如何設置動態求和 Excel設置動態求和方法
1789
2025-04-04
-
Java 代碼
查看代碼
001
十進制轉成十六進制:
002
003
Integer.toHexString(int?i)
004
005
十進制轉成八進制
006
007
Integer.toOctalString(int?i)
008
009
十進制轉成二進制
010
011
Integer.toBinaryString(int?i)
012
013
十六進制轉成十進制
014
015
Integer.valueOf("FFFF",16).toString()
016
017
八進制轉成十進制
018
019
Integer.valueOf("876",8).toString()
020
021
二進制轉十進制
022
023
Integer.valueOf("0101",2).toString()
024
025
026
027
有什么方法可以直接將2,8,16進制直接轉換為10進制的嗎?
028
029
java.lang.Integer類
030
031
parseInt(String s,?int?radix)
032
033
使用第二個參數指定的基數,將字符串參數解析為有符號的整數。
034
035
examples from jdk:
036
037
parseInt("0",?10) returns?0
038
039
parseInt("473",?10) returns?473
040
041
parseInt("-0",?10) returns?0
042
043
parseInt("-FF",?16) returns -255
044
045
parseInt("1100110",?2) returns?102
046
047
parseInt("2147483647",?10) returns?2147483647
048
049
parseInt("-2147483648",?10) returns -2147483648
050
051
parseInt("2147483648",?10)?throws?a NumberFormatException
052
053
parseInt("99",throws?a NumberFormatException
054
055
parseInt("Kona",?10)?throws?a NumberFormatException
056
057
parseInt("Kona",?27) returns?411787
058
059
060
061
進制轉換如何寫(二,八,十六)不用算法
062
063
Integer.toBinaryString
064
065
Integer.toOctalString
066
067
Integer.toHexString
068
069
070
071
072
073
例二
074
075
076
077
public?class?Test{
078
079
public?static?void?main(String args[]){
080
081
082
083
int?i=100;
084
085
String binStr=Integer.toBinaryString(i);
086
087
String otcStr=Integer.toOctalString(i);
088
089
String hexStr=Integer.toHexString(i);
090
091
System.out.println(binStr);
092
093
094
095
}
096
097
098
099
100
101
102
103
例二
104
105
public?class?TestStringFormat {
106
107
public?static?void?main(String[] args) {
108
109
if?(args.length ==?0) {
110
111
System.out.println("usage: java TestStringFormat ");
112
113
System.exit(0);
114
115
}
116
117
118
119
Integer factor = Integer.valueOf(args[0]);
120
121
122
123
String s;
124
125
126
127
s = String.format("%d", factor);
128
129
System.out.println(s);
130
131
s = String.format("%x", factor);
132
133
System.out.println(s);
134
135
s = String.format("%o", factor);
136
137
System.out.println(s);
138
139
}
140
141
}
142
143
144
145
146
147
148
149
其他方法:
150
151
152
153
Integer.toHexString(你的10進制數);
154
155
例如
156
157
String temp = Integer.toHexString(75);
158
159
輸出temp就為 4b
160
161
162
163
164
165
166
167
//輸入一個10進制數字并把它轉換成16進制
168
169
import?java.io.*;
170
171
public?class?toHex{
172
173
174
175
public?static?void?main(String[]args){
176
177
178
179
int?input;//存放輸入數據
180
181
//創建輸入字符串的實例
182
183
BufferedReader strin=new?BufferedReader(new?InputStreamReader(System.in));
184
185
System.out.println("請輸入一個的整數:");
186
187
String x=null;
188
189
try{
190
191
x=strin.readLine();
192
193
}catch(IOException ex){
194
195
ex.printStackTrace();
196
197
}
198
199
input=Integer.parseInt(x);
200
201
System.out.println ("你輸入的數字是:"+input);//輸出從鍵盤接收到的數字
202
203
204
205
System.out.println ("它的16進制是:"+Integer.toHexString(input));//用toHexString把10進制轉換成16進制
206
207
}
208
209
}
Java
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。