- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将一个字符串转换为十六进制字符串,我想将其转换为八进制字符串
我是这样做的
String s="I found the reason 2 days ago i was too bussy to update you.The problem was that the UDHL was missing. I should have added 06 at the beginning. it all works fine.For some reason I thought kannel adds this by itself (not very difficult...), but now I know it doesn't...";
String hex = String.format("%040x", new BigInteger(1, s.getBytes("UTF-8")));
输出是
4920666f756e642074686520726561736f6e203220646179732061676f20692077617320746f6f20627573737920746f2075706461746520796f752e5468652070726f626c656d20776173207468617420746865205544484c20776173206d697373696e672e20492073686f756c6420686176652061646465642030362061742074686520626567696e6e696e672e2020697420616c6c20776f726b732066696e652e466f7220736f6d6520726561736f6e20492074686f75676874206b616e6e656c2061646473207468697320627920697473656c6620286e6f74207665727920646966666963756c742e2e2e292c20627574206e6f772049206b6e6f7720697420646f65736e27742e2e2e
我需要将十六进制字符串转换为八进制字符串。我试过这样
String octal = Integer.toOctalString(Integer.parseInt(hex,16));
但正如预期的那样,它给了我数字格式异常,因为十六进制字符串中有一些字符。
我想知道如何将十六进制字符串转换为八进制字符串。
最佳答案
根据评论中的讨论,您想单独转换每个字节并将它们转换为八进制:
String s = "My string to convert";
byte[] bytes = s.getBytes("UTF-8");
for (byte b : bytes) {
String octalValue = Integer.toString(b, 8);
// Do whatever
}
关于java - java中如何将十六进制字符串转换为八进制字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31069857/
需要帮助将这些给定的数字打印成星号,但我是编程新手;我该怎么做? #include int main(void) { int a[5]={20,1,5,15,12}; int i=0
使用 Delphi XE 2 我试图确定缩放方向以将缩放效果应用于图像(TImage),但没有找到执行此操作的函数,并且图像的 OnGesture 事件中的 EventInfo 属性没有此信息. 我见
我不知道制服在内存中是如何表示的。 制服似乎会占用宝贵的寄存器空间,但它们最终会传入/通过/传出到全局内存中,对吗? 制服不用时情况会发生变化吗?编译器可以将它们优化掉吗?--在这种情况下,我已经将无
我正在尝试在名为“timeclock”的模型上记录“time_in”和“time_out”记录。这是我想做但无法开始工作的事情! 检查最后一个时钟条目,看看它是否同时填充了“time_in”和“tim
我想听听您如何解决这种编程任务!?每种类型(OPER = 1 类型)对应一种特定的信息。 这只是大约 10 个具有相同结构的规范之一。首选创建这些“转换器”(协议(protocol))的通用方法。 最
我正在使用 Rest API(NodeJS、Express)和 PostgreSQL 制作 React-Native 应用。 在我的本地机器上托管时一切正常。当 API 托管在我的机器上并且 Post
我是一名优秀的程序员,十分优秀!