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

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

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

問題描述

我希望能夠?qū)⒆址?帶有單詞/字母)轉(zhuǎn)換為其他形式,例如二進制.我將如何去做這件事.我正在使用 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() 獲取底層字節(jié),然后以其他形式呈現(xiàn)這些字節(jié)(十六進制,二進制無論如何).

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

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)換成二進制,這里舉個例子:

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

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

'foo' to binary: 01100110 01101111 01101111 

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

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲一区视频在线 | 欧美日韩综合视频 | 北条麻妃一区二区三区在线视频 | 国产视频一区二区在线观看 | 精品一区二区久久久久久久网站 | 久久久九九 | 久干网 | 色资源在线视频 | 久久久久久色 | 91免费版在线观看 | 欧美激情视频一区二区三区免费 | 秋霞在线一区二区 | 欧美亚洲另类丝袜综合网动图 | 一区二区三区在线观看免费视频 | 成人影院一区二区三区 | 免费污视频 | 日韩中文欧美 | 免费久久网 | 久久久久久久香蕉 | 国产精品99久久久久久动医院 | 欧美aa在线| 中文字幕免费中文 | 中文字幕一区二区三 | 91欧美激情一区二区三区成人 | 二区国产 | 精品国产18久久久久久二百 | 中文字幕精品一区 | 日韩欧美一级精品久久 | 91精品91久久久 | 日韩欧美在线视频播放 | 国产精品久久国产精品 | 亚洲免费精品 | 综合久久久久久久 | 久久精品91久久久久久再现 | 欧美日韩综合视频 | 亚洲精品视频一区 | 成人精品国产一区二区4080 | 粉嫩高清一区二区三区 | 国产激情毛片 | www.精品国产 | 古装三级在线播放 |