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

问题描述

您好我能够转换 ASCII 使用字符串为二进制一个的BinaryWriter ..如 10101011 。需要我回来转换二进制 ---> ASCII 字符串..任何想法怎么办呢?

Hi i was able to convert a ASCII string to binary using a binarywriter .. as 10101011 . im required back to convert Binary ---> ASCII string .. any idea how to do it ?

推荐答案

这应该做的伎俩......或者至少让你开始...

This should do the trick... or at least get you started...

public Byte[] GetBytesFromBinaryString(String binary)
{
  var list = new List<Byte>();

  for (int i = 0; i < binary.Length; i += 8)
  {
    String t = binary.Substring(i, 8);

    list.Add(Convert.ToByte(t, 2));
  }

  return list.ToArray();
}

在二进制串已被转换为一个字节数组,玩完以

Once the binary string has been converted to a byte array, finish off with

Encoding.ASCII.GetString(data);

所以...

var data = GetBytesFromBinaryString("010000010100001001000011");
var text = Encoding.ASCII.GetString(data);

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

09-18 05:55