Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- namespace Auxilio
- {
- class Program
- {
- static void Main(string[] args)
- {
- do
- {
- Stack quociente;
- int.TryParse(Console.ReadLine(), out int numeroDecimal);
- GetQuocientesHex(out quociente, numeroDecimal);
- string oh;
- TransformToHex(quociente, out oh);
- Console.WriteLine(oh);
- Console.WriteLine("1 to continue...");
- } while (Console.ReadLine().Equals("1"));
- }
- public static void TransformToHex(Stack stack, out string numberT)
- {
- numberT = "";
- foreach(object o in stack)
- {
- int number = (int)o;
- if(MaiorDez(number))
- {
- numberT += HexToDec(number);
- } else
- {
- numberT += number.ToString();
- }
- }
- }
- public static void GetQuocientesHex(out Stack stack, int dec)
- {
- stack = new Stack();
- int r = dec / 16; // 70
- int q = dec % 16; // 8
- do
- {
- stack.Push(q); // 4 6 8
- q = r % 16; //
- r /= 16; // 0
- } while (r != 0);
- stack.Push(q);
- }
- public static bool MaiorDez(int a)
- {
- return a >= 10;
- }
- public static char HexToDec(int dec)
- {
- // ASCII A == 65 -> true
- return (char)(65 + (dec - 10));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement