簡體   English   中英

如何在Java中重新獲得字節的十六進制值?

[英]How to regain the hex value of a byte in java?

private static byte[]theTestText ={0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,(byte) 0x88,(byte) 0x99,(byte) 0xAA,(byte) 0xBB,(byte) 0xCC,(byte) 0xDD,(byte) 0xEE,(byte) 0xFF};

String str= new String(theTestText); // converted the byte array to string
char ch = str.charAt(8); // extracting a specific character from string

我想從原始字節數組即0x88中定義的字符“ ch”中獲取十六進制值。 有什么辦法做到這一點?

要獲取字符串中的六進制值:

String str= new String(theTestText); // converted the byte array to string
char ch = str.charAt(8); // extracting a specific character from string
String hex = String.format("%04x", (int) ch); // Converting the char to a string with its hexadecimal value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM