java 二进制as_Java中的二进制文本
這是我的(在Java 8上可以正常工作):
String input = "01110100"; // Binary input as String
StringBuilder sb = new StringBuilder(); // Some place to store the chars
Arrays.stream( // Create a Stream
input.split("(?<=\\G.{8})") // Splits the input string into 8-char-sections (Since a char has 8 bits = 1 byte)
).forEach(s -> // Go through each 8-char-section...
sb.append((char) Integer.parseInt(s, 2)) // ...and turn it into an int and then to a char
);
String output = sb.toString(); // Output text (t)
并將壓縮方法打印到控制臺:
Arrays.stream(input.split("(?<=\\G.{8})")).forEach(s -> System.out.print((char) Integer.parseInt(s, 2)));
System.out.print('\n');
我相信有“更好”的方法可以做到這一點(diǎn),但這是您可能獲得的最小方法。
總結(jié)
以上是生活随笔為你收集整理的java 二进制as_Java中的二进制文本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: S3C2440中断解析和基于WINCE操
- 下一篇: 苹果iOS 16支持消息撤回编辑 网友: