0

I need to take an input from the user, turn all the chars to their decimal value and display the as one string without spaces, then turn it into a string and display it, and afterwards take the number string and turn back to the original string.

A."Hello World" - string

B."72101108108111 87111114108100" - string

C."7210110810811187111114108100" (Processed and displayed) - int

D."72101108108111 87111114108100" - string

E."Hello World" - string

I got to this stage :

string input = Console.ReadLine();
byte[] array = Encoding.ASCII.GetBytes(input);

It's not much but its my first try at creating a program.

  • 1
    And what's the question..? – Sean Feb 02 '14 at 16:04
  • What you are attempting to do is not possible. You need to choose a different format. How can you tell where one byte ends, and the next one begins? – David Heffernan Feb 02 '14 at 16:04
  • You're going to run into serious problems trying to store 7210110810811187111114108100 as an int. Even Int64.MaxValue is 9 orders of magnitude smaller than that. – spender Feb 02 '14 at 16:07
  • 1
    Take a look at this: http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa – David Heffernan Feb 02 '14 at 16:08
  • 1
    This seems not possible to me. Let's takes `72` which is ascii code of `H` character. And you converted to string as `"72"`. After this process, how compiler can know this belongs on only one character? What is compiler divide these as 2 ascii code like `"7"` and `"2"` ? – Soner Gönül Feb 02 '14 at 16:08
  • Is it possible to create a dictionary which replace the chars with their decimal value? – user3263113 Feb 02 '14 at 16:15
  • I agree that step C is not possible with a normal int, and that step E isn't possible unless the ASCII values are padded with leading zeros so they're a predictable length. – keshlam Feb 02 '14 at 16:23
  • Each computer has its limits! You cannot do UNLIMITED number calculations. – Aniket Inge Feb 02 '14 at 17:18

1 Answers1

0

here is a example using decimal. but you could also use System.Numerics.BigInteger with its ToString and Parse functions for bigger numbers

http://msdn.microsoft.com/en-us/library/system.numerics.biginteger(v=vs.110).aspx

using System;

namespace big_number
{
class Program
{
    static void Main(string[] args)
    {
        decimal d = 0;

        begining:
        try {d = Convert.ToDecimal(Console.ReadLine()); }//<------ HERE IT IS!!!
        catch (Exception EX)// look up what exceptions you want to catch
        { 
            Console.WriteLine("try again\r\n\n" + EX.Message);//display error (if you want)
            d = 0;//just incase
            goto begining; // do not run this code outside of debugger you may get caught in inifinite loop
        }

        //and back again
        string s = "" + d;

        Console.WriteLine(s);//we could just pass d

        Console.ReadLine();
    }
}
}
RadioSpace
  • 953
  • 7
  • 15