我有一个字节数组,我将其转换为如下字符串:
<input type="number" id="job-priority" min="1" max="99" pattern="[0-9]+" placeholder="1 (High) — 99 (Low)" style="width:186px; padding-left:14px; text-align:center;">
document.getElementById('job-priority').addEventListener('input', function () {
// Check that characters typed into job priority field are valid.
if (!document.getElementById('job-priority').validity.valid) {
var value = document.getElementById('job-priority').value;
value = value.slice(0,-1);
document.getElementById('job-priority').value = value;
}
});
document.getElementById('job-priority').addEventListener('change', function () {
// Check that number entered into job priority stays within limits.
var value = Number(document.getElementById('job-priority').value);
var min = Number(document.getElementById('job-priority').min);
var max = Number(document.getElementById('job-priority').max);
if (value < min)
document.getElementById('job-priority').value = min;
else if (value > max)
document.getElementById('job-priority').value = max;
});
我在我的字符串puck_data中检索了2个值,我想得到我的数组的第一个和第二个值。我怎么能这样做?
答案 0 :(得分:0)
由于您在注释中设置的示例不是可打印字符,我认为您想要一种方法来打印数组的外观。
此示例将向您显示将字节值转换为十进制解释的数组内容,并给出基础:
- 访问数组中的字节 - 如何将二进制值转换为十进制无符号字符串表示 - 如何使用StringBuilder。
byte[] manufacturerData = new byte [] {(byte) 254,26};
byte byte1 = manufacturerData[0];
byte byte2 = manufacturerData[1];
StringBuilder sb = new StringBuilder();
sb.append("[")
.append((int) (0x00FF & byte1))
.append(",")
.append((int) (0x00FF & byte2))
.append("]");
String puck_data = sb.toString();
System.out.println(puck_data);