是否有可用於在java中將八進制轉換爲十六進制的函數?在Java中將八進制轉換爲十六進制的函數
1
A
回答
0
String octalNo="037";
System.out.println(Long.toHexString(Long.parseLong(octalNo,8)));
3
這一切都假定你的電話號碼,之前和之後,將被存儲在一個字符串(因爲它是沒有意義的談論基地一個int /整數):
Integer.toHexString(Integer.parseInt(someOctalString, 8));
5
有沒有單一的方法,但你可以很容易地做到這一點通過兩個步驟:
- 解析您的
String
含八進制值到int
(或long
,取決於預期範圍) - 將
int
/long
設置爲十六進制的格式String
。
這兩個步驟可以分別使用Integer.parseInt(String, int)
和Integer.toString(int, int)
來完成。確保使用雙參數版本,並分別將8和16分別傳遞給八進制和十六進制。
+0
如果包含其他答案包含的簡單單行代碼解決方案,我會對此答案進行投票。這個答案只是圍繞它跳舞。 –
+3
@Erick這實際上是upvote * this *的原因:它需要OP爲自己思考和嘗試。 –
0
String input = "1234";
String hex = Long.toHexString(Long.parseLong(input,8));
0
/**
* This method takes octal input and convert it to Decimal
*
* @param octalInput
* @return converted decimal value of the octal input
*/
public static int ConvertOctalToDec(String octalInput)
{
int a;
int counter = 0;
double product = 0;
for (int index = octalInput.length() ; index > 0 ; index --)
{
a = Character.getNumericValue(octalInput.charAt(index - 1));
product = product + (a * Math.pow(8 , counter));
counter ++ ;
}
return (int) product;
}
/**
* This methods takes octal number as input and then calls
* ConvertOctalToDec to convert octal to decimal number then converts it
* to Hex
*
* @param octalInput
* @return Converted Hex value of octal input
*/
public static String convertOctalToHex(String octalInput)
{
int decimal = ConvertOctalToDec(octalInput);
String hex = "";
while (decimal != 0)
{
int hexValue = decimal % 16;
hex = convertHexToChar(hexValue) + hex;
decimal = decimal/16;
}
return hex;
}
相關問題
- 1. 將八進制數轉換爲十進制和十六進制
- 2. 將十進制數轉換爲二進制/十六進制/八進制符號
- 3. 將二進制,十六進制和八進制轉換爲java數據類型
- 4. 將十進制轉換爲二進制,八進制和十六進制?
- 5. 轉換爲八進制,二進制和十六進制在JavaScript
- 6. 將十進制轉換爲十六進制和十六進制
- 7. 轉換十六進制,十進制,八進制和ASCII?
- 8. 將十六進制轉換爲二進制到十六進制?
- 9. 十進制轉換爲十六進制的轉換(Java)的
- 10. 在Lex中將八進制數轉換爲十進制數
- 11. 將excel中的Unicode十六進制數轉換爲十進制
- 12. 在Arduino上將整數/十進制轉換爲十六進制?
- 13. 在Java中將十六進制數轉換爲十進制數(Android)
- 14. 將十進制轉換爲十六進制/二進制
- 15. 八進制轉換爲十六進制錯誤
- 16. 將字符串轉換爲十六進制到十六進制
- 17. 整數轉換爲十六進制Java
- 18. 在Visual C++中將十進制值轉換爲十六進制
- 19. 在Python中將十六進制值轉換爲十進制
- 20. 在程序集中將十進制轉換爲十六進制
- 21. 在VB6中將十六進制值轉換爲十進制值
- 22. 在Lua 4中將十進制轉換爲十六進制?
- 23. 在Swift中將十六進制轉換爲十進制
- 24. 如何在bash中將十進制轉換爲十六進制?
- 25. 在R中將十六進制轉換爲十進制
- 26. 將十六進制轉換爲十進制在swift中
- 27. 如何在Python中將十六進制轉換爲十進制?
- 28. 將二進制十進制轉換爲十六進制,二進制和八進制字符串
- 29. 將八進制數轉換爲十進制數的算法?
- 30. 將八進制和十六進制數字轉換爲基數10
@ Mr.L鏈接不工作現在:) – randombee
@randombee是的,它似乎是一個DNS不存在了。刪除了我的評論。 –