using System;
using System.Collections.Generic;
using System.Text;
namespace Demo {
class toBinary {
static void Main(string[] args) {
int val = 1010, myBinary, remainder;
int myDecimal = 0, baseVal = 1;
myBinary = val;
while (val > 0) {
remainder = val % 10;
myDecimal = myDecimal + remainder * baseVal;
val = val / 10;
baseVal = baseVal * 2;
}
Console.Write("Binary Number : " + myBinary);
Console.Write("/nConverted to Decimal: " + myDecimal);
Console.ReadLine();
}
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/265892.html