Conversão de Decimal para HexaDecimal

Projeto Conversão de Decimal para HexaDecimal

Esse projeto foi feito em C# no consolo Application

converte números de 0 ha 300 de decimal para hexa




código em no GIT acessar no link abaixo


https://github.com/ELETICA-PINHO/Conevet_Dec_hexa

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. /* Autor: ALESSANDRO PINHO
  7.  * DATA : 23-05-2019
  8.  * PROJETO : FACULDADE
  9.  * DESCRIÇÃO
  10.  *
  11.  * CONVERTE NUMEROS DE 0 HÁ 300
  12.  * CASO HAJA NECESSEIDA PODE SER AUTERADO PRIMEIRO IF
  13.  * PARA ACEITAR VALOR DE 0 HA 4095
  14.  * ESSE PROGRMA SÓ CONVERTE HEXA D 3 DIGITOS OU SEJA
  15.  * EX  DEC 4095 HEXA FF
  16.  * DEX 4097 ERRO 1000
  17.  *
  18.  *
  19.  */
  20. namespace Converte_Decimal_Hexadecimal
  21. {
  22. class Program
  23. {
  24. static void Main(string[] args)
  25. {
  26. //vetor de hexa 0 a 15
  27. char[] vetor_Hexa = new char[] { '0''1''2''3''4''5''6''7''8''9''A''B''C''D''E''F' };
  28. //variaveis de processamento
  29. char convertQ = ' ';
  30. char convertR = ' ';
  31. string convert = " ";
  32. int convert_quociente = 0;
  33. int convert_resto = 0;
  34. int N_digitado = 0;
  35. int base_divisor = 16;
  36. char resto1 = ' ';
  37. int quociente1 = 0;
  38. Console.WriteLine("Digite um numero entre 0 e 300 !! ");
  39. N_digitado = Convert.ToInt32(Console.ReadLine());
  40. if (N_digitado <= 0 || N_digitado <= 300)  // condição numero
  41. {
  42. convert_quociente = N_digitado / base_divisor;
  43. convert_resto = N_digitado % base_divisor;
  44. if (N_digitado <= 256) // ATE 256 DECIMAIS
  45. {
  46. convertQ = vetor_Hexa[convert_quociente];   //VETOR CONVERSÃO
  47. convertR = vetor_Hexa[convert_resto];       //VETOR CONVERSÃO
  48. convert = Convert.ToString(convertQ) + Convert.ToString(convertR);  //MONTAGEM HEXA AT 256
  49. }
  50. if (N_digitado > 256)
  51. {
  52. quociente1 = convert_quociente;
  53. resto1 = vetor_Hexa[convert_resto];  //menos sequinativo 3
  54. if (convert_quociente >= 16)
  55. {
  56. convertQ = vetor_Hexa[quociente1 / base_divisor];  ////menos sequinativo 1
  57. convertR = vetor_Hexa[quociente1 % base_divisor];  ////menos sequinativo 2
  58. }
  59. convert = Convert.ToString(convertQ) + Convert.ToString(convertR) + Convert.ToString(resto1);
  60. //                                1                            2                             3
  61. }
  62. //  Console.WriteLine("Quociente = " + convert_quociente);
  63. //    Console.WriteLine("Resto = "     + convert_resto);
  64. /////   Console.WriteLine("Quociente com = " + convertQ);
  65. ///   Console.WriteLine("Resto com = " + convertR);
  66. Console.WriteLine("HEXA-DECIMAL >>> " + convert);
  67. Console.ReadLine();
  68. } // if 0 300
  69. else
  70. {
  71. Console.WriteLine("Valor não é permitido tente novamente, 0 a 300");
  72. Console.ReadLine();
  73. }  // else 0 300
  74. }
  75. }