您现在的位置是:网站首页> 编程资料编程资料

将新型冠状病毒转二进制的代码(首发)_其它综合_

2023-05-27 306人已围观

简介 将新型冠状病毒转二进制的代码(首发)_其它综合_

视频

将“新型冠状病毒”转换为二进制???

视频地址: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;i

Php

function StrToBin($str){
 $arr = preg_split('/(?

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 
#include 
using namespace std;
void outc(char c)
{
 unsigned char k = 0x80
 for (int i=0; i<8; 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;

总结

以上所述是小编给大家介绍的将新型冠状病毒转二进制的代码,希望对大家有所帮助!

-六神源码网