How do you convert a string to ascii to binary in C#?

后端 未结 5 1709
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 23:01

A while back (freshman year of high school) I asked a really good C++ programmer who was a junior to make a simple application to convert a string to binary. He gave me the

5条回答
  •  不知归路
    2020-12-03 23:21

    It's not clear precisely what you want, but here's what I think you want:

    return Convert.ToString(int.Parse(str), 2); // "5" --> "101"
    

    This isn't what the C++ code does. For that, I suggest:

    string[] binaryDigits = str.Select(c => Convert.ToString(c, 2));
    foreach(string s in binaryDigits) Console.WriteLine(s);
    

提交回复
热议问题