1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| {
var sle = "abc".getBytes(StandardCharsets.UTF_16LE);
System.out.println(Bytes.asList(sle).stream()
.map(b -> StringUtils.leftPad(Integer.toBinaryString(b), 8, '0'))
.collect(Collectors.joining(",")));
// out 01100001,00000000,01100010,00000000,01100011,00000000
System.out.println(BinaryCodec.toAsciiString(sle).replaceAll("(.{8})", "$1,"));
// out 00000000,01100011,00000000,01100010,00000000,01100001,
}
{
var sbe = "abc".getBytes(StandardCharsets.UTF_16BE);
System.out.println(Bytes.asList(sbe).stream()
.map(b -> StringUtils.leftPad(Integer.toBinaryString(b), 8, '0'))
.collect(Collectors.joining(",")));
// out 00000000,01100001,00000000,01100010,00000000,01100011
System.out.println(BinaryCodec.toAsciiString(sbe).replaceAll("(.{8})", "$1,"));
// out 01100011,00000000,01100010,00000000,01100001,00000000,
} |