Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Binary Hex Decimal Systems
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { long number = 473; //Convert Decimal to Binary Console.WriteLine("Binary: " + ConvertToBinary(number)); //Convert Binary to Decimal Console.WriteLine("Decimal: " + ConvertToDecimal(number)); //Decimal to Hex string hexValue = number.ToString("X"); Console.WriteLine(hexValue); //Hex to Decimal long hex_int = strtol(1D9, NULL, 16); Console.WriteLine(hex_int); } //Method to convert number to Binary public static long ConvertToBinary(long number) { string result = ""; long remainder = 0; string remainderString; while (number != 0) { remainder = number % 2; //Console.WriteLine(remainder); remainderString = remainder.ToString(); result = result + remainder; number = number /2; } long finalResult = Convert.ToInt64(result); return finalResult; } public static double ConvertToDecimal(long number) { long lastNumber = 0; double result = 0; for (int i = 0; i < 10; i++) { lastNumber = number % 10; if (lastNumber != 0 && lastNumber !=1) { Console.WriteLine("This is not a correct Binary number..."); return 0; } if (lastNumber ==1) result = result + Math.Pow(2, i); number = number / 10; } return result; } } }
run
|
edit
|
history
|
help
0
null enum value check is false
tesyyyyy
sum of two array elements
Fórum SO ➡ Merging 2 lists by Name and adding their Values, using LINQ ♦
Found many section of times intersect (Question version)
Singleton Design Pattern
SumOfEvens
Round Program
program
bla bla