#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    313
    Rep Power
    0

    Programming Puzzle - Binary to Decimal conversion


    Write C program that:

    1. Takes as input some null terminated char(acter) string with '0's and '1's
    containing binary representation of some huge positive integer;

    2. As output, it produces also char string with decimal representation of the above integer.

    Remark: input may be very large (say 10 MB),
    so it is impossible to store the above integer in a variable (int or long long).

    Positive thinking: you have enough RAM.
    Last edited by leszek31417; September 5th, 2011 at 04:20 AM.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,898
    Rep Power
    509

    gmp


    Investigate gmp. I pretty sure this problem is trite using the gnu multi-precision library.
  4. #3
  5. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,898
    Rep Power
    509

    j solution


    In j, the solution is:

    #. x: '1' = fread 'text.file.of.only.1.and.0'

    write a program in any language that pipes this input to your shell:

    Code:
    jconsole -js "#. x: '1' = fread 'text.file.of.only.1.and.0'"
    and you'll have your answer as a text decimal when you read from same duplex pipe.

    Discover j at www.jsoftware.com . Some of you will like it.

IMN logo majestic logo threadwatch logo seochat tools logo