File Conversion

This is a discussion on File Conversion within the C# Programming forums, part of the General Programming Boards category; Hi i would like to know if it is possible to convert any file input into a number such as ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    3

    File Conversion

    Hi i would like to know if it is possible to convert any file input into a number such as a long or integer and back into the file. Im not asking for you to program this for me id just like to know how you would do this in theory.

    The 2 theories i have tried so far are 1. To convert the file into a byte array then into a long this was unsuccessful. 2. To convert the file into a string then into a long/integer this was also unsuccessful. The reason im posting is i would like your input into how you would go about doing this or if it is even possible. I understand that the number generated from this file would be huge so also realise that some larger file may need to be split into smaller files to do this.

    I am only asking for your theories here on how to do this but code snipets are always welcome.

    Thank you in advanced

    dxkpax

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Try one or more of those theories yourself and then when you are not successful come back with a specific question and we will help.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    3
    I have been trying different theories and still am unsuccessful. I do however have a more specific question.

    Is it possible to convert a Base64String to a number (int/long) i have tried using ToInt64 with no success. here is my current code.

    Code:
    class Program
        {
            static void Main(string[] args)
            { 
                
                FileStream fs1;
                byte[] b1;
                string file1 = @"C:\temp\1.txt";
                string b64string;
    
                    try
                    {
                        fs1 = new System.IO.FileStream(file1, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        b1 = new Byte[fs1.Length];
                        long bytesRead = fs1.Read(b1, 0, (int)fs1.Length);
                        fs1.Close();
                        b64string = System.Convert.ToBase64String(b1,0,b1.Length);
                        long l1 = System.Convert.ToInt64(b64string);
                        Console.WriteLine(b64string);               
                    }
                    catch (System.Exception exp)
                    {
                        System.Console.WriteLine("{0}", exp.Message);
                        return;
                    }
            }
        }
    If not is there a different way to convert the file to a number with no data loss when converting the number back to a file.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    What does your input file look like? Is it a text file that you're trying to read in and convert to an integer type? Can you post the contents of the input file (unless it's binary of course)?
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    3
    For the input file i would like to be able to use any file type. This is why i was converting the file to a Base64String first.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 09:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21