[英]Convert bytes to String
We receive from bluetooth device this output: byte[] bytes = intent.getStringExtra(BluetoothLeService.EXTRA_DATA).getBytes(); 我们从蓝牙设备接收到以下输出:byte [] bytes = intent.getStringExtra(BluetoothLeService.EXTRA_DATA).getBytes();
and the output is: enter image description here 输出为: 在此处输入图像描述
How I can transform bytes[] to String[] in format HEX without losing "CE" chars in the picture? 如何在不丢失图片中的“ CE”字符的情况下以十六进制格式将bytes []转换为String []?
If your bytes are just plain text, then you can do 如果您的字节只是纯文本,那么您可以
new String(bytes, "UTF-8");
If your bytes create a hex string, convert that hex string to another byte[]
by doing 如果您的字节创建了一个十六进制字符串,请执行以下操作将该十六进制字符串转换为另一个byte[]
new String(DatatypeConverter.parseHexBinary(new String(bytes)), "UTF-8")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.