二进制转换字符串为二进制 [英] Convert Binary String to Binary

查看:166
本文介绍了二进制转换字符串为二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么写成二进制字符串,转换为二进制(以字节数组)?

How do I convert a String written as Binary, to binary (in byte array)?

如果我有一个字符串:

字符串二进制=0000

我要的二进制数据 0000

下面是当我设定的二进制字节数组(这反过来又返回48,这是ASCII)

below is what happens when I set the binary to a byte array (which in turn returns 48, which is ASCII)


    二进制字符串:0000
    二进制字节数组:48
    二进制字节数组:48
    二进制字节数组:48
    二进制字节数组:48

我不擅长解释,所以希望上面的例子就足以告诉你我想要什么。

I'm not good at explaining so hopefully the above example was enough to tell you what I want.

编辑:这是将数据设置成二进制文件

This is to set the data into a binary file.

推荐答案

使用这样的:

    System.out.println(Integer.toBinaryString(Integer.parseInt("000",2))); // gives 0
    System.out.println(Integer.toBinaryString(Integer.parseInt("010",2))); // gives 10
    System.out.println(Integer.toBinaryString(Integer.parseInt("100",2))); // gives 100

这篇关于二进制转换字符串为二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆