視頻
將“新型冠狀病毒”轉(zhuǎn)換為二進(jìn)制???
視頻地址:https://www.bilibili.com/video/av86588592
Java
public class Main {
public static void main(String[] args) {
String str = toBinary("新型冠狀病毒");
System.out.println(str);
}
private static String toBinary(String str) {
char[] strChar = str.toCharArray();
StringBuilder result = new StringBuilder();
for (char c : strChar) {
result.append(Integer.toBinaryString(c));
}
return result.toString();
}
}
JavaScript
function strToBinary(str){
var result = [];
var list = str.split("");
for(var i=0;ilist.length;i++){
var item = list[i];
var binaryStr = item.charCodeAt().toString(2);
result.push(binartStr);
}
return result.join("");
}
console.log(strToBinary("新型冠狀病毒"));
Php
function StrToBin($str){
$arr = preg_split('/(?!^)(?!$)/u', $str);
foreach($arr as $v){
$temp = unpack('H*', $v);
$v = base_convert($temp[1], 16, 2);
unset($temp);
}
return join(' ',$arr);
}
echo StrToBin("新型冠狀病毒");
Python
def encode(s):
return ' '.join([bin(ord(c)).replace('0b', '') for c in s])
def decode(s):
return ''.join([chr(i) for i in [int(b, 2) for b in s.split(' ')]])
var1 = encode("新型冠狀病毒")
print(var1)
print(decode(var1))
var1Arr = var1.split(" ")
for i in range(len(var1Arr)):
print(var1Arr[i])
C++
#include iostream>
#include stdlib.h>
using namespace std;
void outc(char c)
{
unsigned char k = 0x80
for (int i=0; i8; i++, k >>= 1){
if (c k){
printf("1");
} else{
printf("0");
}
}
printf(" ");
}
int main (){
char str[]="新型冠狀病毒";
for(int i=0; str[i]; i++){
outc(str[i]);
}
system("pause");
return true;
總結(jié)
以上所述是小編給大家介紹的將新型冠狀病毒轉(zhuǎn)二進(jìn)制的代碼,希望對大家有所幫助!
您可能感興趣的文章:- python+selenium定時爬取丁香園的新型冠狀病毒數(shù)據(jù)并制作出類似的地圖(部署到云服務(wù)器)
- node爬取新型冠狀病毒的疫情實時動態(tài)
- Python抓新型冠狀病毒肺炎疫情數(shù)據(jù)并繪制全國疫情分布的代碼實例
- Python實現(xiàn)新型冠狀病毒傳播模型及預(yù)測代碼實例
- PHP實現(xiàn)新型冠狀病毒疫情實時圖的實例
- Python實現(xiàn)實時數(shù)據(jù)采集新型冠狀病毒數(shù)據(jù)實例
- python模擬預(yù)測一下新型冠狀病毒肺炎的數(shù)據(jù)
- 使用Python制作新型冠狀病毒實時疫情圖
- pyecharts繪制中國2020肺炎疫情地圖的實例代碼