久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在Java中將字符串(如testing123)轉換為二進制

Convert A String (like testing123) To Binary In Java(在Java中將字符串(如testing123)轉換為二進制)
本文介紹了在Java中將字符串(如testing123)轉換為二進制的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我希望能夠將字符串(帶有單詞/字母)轉換為其他形式,例如二進制.我將如何去做這件事.我正在使用 BLUEJ (Java) 進行編碼.謝謝

I would like to be able to convert a String (with words/letters) to other forms, like binary. How would I go about doing this. I am coding in BLUEJ (Java). Thanks

推薦答案

通常的方法是使用 String#getBytes() 獲取底層字節,然后以其他形式呈現這些字節(十六進制,二進制無論如何).

The usual way is to use String#getBytes() to get the underlying bytes and then present those bytes in some other form (hex, binary whatever).

請注意,getBytes() 使用默認字符集,因此如果要將字符串轉換為某種特定的字符編碼,則應使用 getBytes(String encoding) 代替,但很多時候(尤其是在處理 ASCII 時)getBytes() 就足夠了(并且具有不拋出已檢查異常的優點).

Note that getBytes() uses the default charset, so if you want the string converted to some specific character encoding, you should use getBytes(String encoding) instead, but many times (esp when dealing with ASCII) getBytes() is enough (and has the advantage of not throwing a checked exception).

具體轉換成二進制,這里舉個例子:

For specific conversion to binary, here is an example:

  String s = "foo";
  byte[] bytes = s.getBytes();
  StringBuilder binary = new StringBuilder();
  for (byte b : bytes)
  {
     int val = b;
     for (int i = 0; i < 8; i++)
     {
        binary.append((val & 128) == 0 ? 0 : 1);
        val <<= 1;
     }
     binary.append(' ');
  }
  System.out.println("'" + s + "' to binary: " + binary);

運行此示例將產生:

'foo' to binary: 01100110 01101111 01101111 

這篇關于在Java中將字符串(如testing123)轉換為二進制的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 黄网站涩免费蜜桃网站 | 国产精品av久久久久久久久久 | 国内精品久久精品 | 在线一区二区国产 | 国产精久久久久久久 | 可以在线看的黄色网址 | 亚洲国产一区在线 | 国产一区二区三区免费 | 亚洲一区中文字幕 | 久久久久国产一区二区三区 | 国产日韩欧美一区 | 国产精品视频导航 | av网站免费观看 | 亚洲综合二区 | 99精品视频一区二区三区 | 成人免费av| 超碰成人免费 | 91在线视频播放 | 午夜精品久久久久久久星辰影院 | 亚洲一区国产精品 | 欧洲精品一区 | 日本午夜在线视频 | 久久无毛 | 日韩精品在线观看网站 | 亚洲在线一区二区三区 | 亚洲一区不卡 | 人人九九精 | 免费视频二区 | 日韩欧美在线一区 | 亚洲一区二区日韩 | 久草福利| 伊人狠狠| 国产91视频一区二区 | 精品九九 | 亚洲国产精品久久久久秋霞不卡 | 久久综合国产精品 | 9999国产精品欧美久久久久久 | 天天拍天天插 | 黄色免费在线观看网址 | 国产成人精品免费视频大全最热 | 成人精品在线观看 |