[英]Name To Decimal To Binary Algorithm
I am trying to make a program that asks you about your name, after that it shows the number of every character of your name according to ASCII table. 我正在尝试制作一个程序,询问您的姓名,然后根据ASCII表显示您姓名的每个字符的数量。 Now I want each number to be converted in to binary and .... I am stuck!
现在,我希望将每个数字都转换为二进制,然后.... :) Please some help!
:)请一些帮助! Here is my code:
这是我的代码:
using System;
namespace DecimalToBinary
{
class DecimalToBinary
{
static void Main()
{
Console.WriteLine("Pleasse, enter your name:");
string name = Console.ReadLine();
foreach (char ch in name)
{
Console.WriteLine("Character {0} is {1} according to ASCII table.", ch, (int)ch);
}
foreach (char ch in name)
{
int decNumber = ch;
Console.WriteLine(decNumber);
}
Console.WriteLine("Enter a number:");
int number = Int32.Parse(Console.ReadLine());
string binary = Convert.ToString(number, 2);
Console.WriteLine(binary);
}
}
}
Do you mean convert each of the ASCII values to binary as well as simple integer? 您的意思是将每个ASCII值都转换为二进制以及简单的整数吗?
foreach (char ch in name)
{
int decNumber = ch;
Console.WriteLine(decNumber);
for (int i = 0; i < name.Length; i++)
{
Console.WriteLine("Enter a number:");
int a = Convert.ToInt32(Console.ReadLine());
var result = Convert.ToString(a, 2);
Console.WriteLine(result);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.