Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication8
- {
- class NumberConvertions
- {
- static void Main(string[] args)
- {
- // http://stackoverflow.com/questions/74148/how-to-convert-numbers-between-hexadecimal-and-decimal-in-c
- // To convert from Decimal to Hex do...
- Console.WriteLine("Моля въведете число");
- int decValue = Convert.ToInt32(Console.ReadLine());
- string hexValue = decValue.ToString("X");
- //Convert.ToInt64(hexValue, 16);
- Console.WriteLine(hexValue);
- // To convert from Hex to Decimal do either...
- int decValue2 = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
- Console.WriteLine(decValue2);
- //string.format("{0:x}", decValue);
- // http://stackoverflow.com/questions/2954962/decimal-to-binary-conversion-in-c
- // To convert from Decimal to Binary do...
- string binary = Convert.ToString(decValue, 2);
- Console.WriteLine(binary);
- // To convert from Binary to Decimal do either..
- // http://stackoverflow.com/questions/2954962/decimal-to-binary-conversion-in-c
- long l = Convert.ToInt64(binary, 2);
- Console.WriteLine(l);
- // Binary to Hex
- // http://stackoverflow.com/questions/5612306/converting-long-string-of-binary-to-hex-c-sharp
- // Hex to binary
- string binarystring = String.Join(String.Empty, hexValue.Select(
- c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')));
- Console.WriteLine(binarystring);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement