久久久久久久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)換為某種特定的字符編碼,則應使用 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 

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

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(liá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(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美在线一级 | 国产婷婷精品 | 欧洲精品视频一区 | 韩日av在线 | 久久久夜色精品亚洲 | 亚洲精品 在线播放 | 国产精品一区二区久久 | 亚洲欧美在线观看视频 | av黄色在线观看 | 伊人网综合在线观看 | 好姑娘高清在线观看电影 | а_天堂中文最新版地址 | 国产精品福利视频 | 欧美性另类 | 性色av网站 | 国产男女猛烈无遮掩视频免费网站 | 日韩中文字幕 | 亚洲精品中文字幕在线观看 | jizz视频 | 成人视屏在线观看 | 天堂资源 | 亚洲精品欧美 | 蜜桃视频一区二区三区 | 久久一二 | 久久精品在线 | 亚洲 中文 欧美 日韩 在线观看 | 久久国产精品久久久久久久久久 | 天堂色区 | 国产福利观看 | www.99精品 | www.4567 | 色婷婷综合久久久久中文一区二区 | 日本一级淫片免费啪啪3 | 欧美精品一区二区三区在线 | 国产精品一区二区三区四区 | 手机看片在线播放 | 精品欧美激情精品一区 | 久久久一区二区三区 | 成人欧美日韩一区二区三区 | 在线国产中文字幕 | 国产一区二区三区在线 |