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

在Java中將字符串(如testing123)轉(zhuǎn)換為二進(jìn)制

Convert A String (like testing123) To Binary In Java(在Java中將字符串(如testing123)轉(zhuǎn)換為二進(jìn)制)
本文介紹了在Java中將字符串(如testing123)轉(zhuǎn)換為二進(jìn)制的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我希望能夠?qū)⒆址?帶有單詞/字母)轉(zhuǎn)換為其他形式,例如二進(jìn)制.我將如何去做這件事.我正在使用 BLUEJ (Java) 進(jìn)行編碼.謝謝

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() 獲取底層字節(jié),然后以其他形式呈現(xiàn)這些字節(jié)(十六進(jìn)制,二進(jìn)制無(wú)論如何).

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).

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

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).

具體轉(zhuǎn)換成二進(jìn)制,這里舉個(gè)例子:

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);

運(yùn)行此示例將產(chǎn)生:

'foo' to binary: 01100110 01101111 01101111 

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

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 中文在线字幕免费观 | 欧美色偷偷 | 午夜在线视频观看日韩17c | 1级黄色大片 | 日韩精品在线看 | 亚洲天码中字 | 69精品视频 | 22精品一区二区三区 | 日本一级黄色大片 | 国产天天操 | 日韩欧美精品在线观看 | 中文字幕第2页 | 免费特级毛片 | 欧美专区在线观看 | 在线视频亚洲 | 亚洲欧美一区二区三区在线 | 国产成人综合在线 | 国产一级片在线 | 国产又粗又猛又黄又爽无遮挡 | 久久久久女人精品毛片九一 | h视频免费在线观看 | 老女人丨91丨九色 | 欧美一级片在线观看 | 在线观看欧美日韩视频 | 国产精品亚洲综合 | 污视频网站在线观看 | 夜夜躁狠狠躁日日躁av | 国产精品视频久久久 | 97人人视频| 成人动漫免费观看 | 日韩精品免费在线观看 | 亚洲精品视频在线播放 | 亚洲精品911 | 伊人999| 韩国av一区二区 | 免费国产精品视频 | 欧美日韩| 中文字幕一区二区三区视频 | 久草视频在线播放 | 高潮毛片又色又爽免费 | 久久国产精品一区二区三区 |