Thread: Not decimal

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    8

    Not decimal

    Hello!

    Can I work with less numbers than ten? For example 5 numbers (2, 4, 6, 7, 8) where the lowest five-digit number, using all the selected numbers, would be 24678. If I increased this number, then the next value would be 24682.

    Thanks
    Fero

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    try using an array:

    int numbers[6] = {0, 2, 4, 6, 7, 8};

    then instead of working with the actual values (2,4,6,7,8), use normal numbers but in base 5 - and then when you have the answer (e.g. 2314 in base 5), just use each digit as an index in the array. so:

    2314
    =
    numbers[2]numbers[3]numbers[1]numbers[4]
    =
    4628

    Now you just have to figure out how to do math in base 5
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I'm having trouble understanding what you're asking.. but I guess I can give it a shot. If this is nothing like what you wanted, please ignore me

    Code:
    int numbers[] = { 2, 4, 6, 7, 8}; 
    long sum = 0;
    
    for (int i = 0; i < 6; i++)
    {
          sum += (numbers[4 - i] * pow(10, i));
    }
    I didn't test this... but it should give you a long representation of 24678;
    Last edited by Dual-Catfish; 06-29-2002 at 04:15 PM.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    Ugh... That's one helluva problem.
    It isn't hard to work with different radixes, but it can be horribly slow.
    One thing you could try is to check after every addition whether any of your digits is above 8, then add one to the next and substract 5 from the original, like this:
    24678
    20234
    --------+
    447AC

    Then, C is more than 8. So, you substract 5, so you get 7, and add one to A, making it B. B is higher than 8, so substract 5 and get 6, add one to 7 making it 8, which is alright. No other number get above 8. The final number is 44878. However, if you have to do all that for every number, stuff gets slow very fast. (I did that once with a radix of 100 to get very large numbers. The result... Ugh. It did get Pi in 13 decimals though )
    Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting 32 bit binary IP to decimal IP (vice-versa)
    By Mankthetank19 in forum C Programming
    Replies: 15
    Last Post: 12-28-2009, 07:17 PM
  2. I need help with decimal to binary Algorithm
    By webznz in forum C Programming
    Replies: 4
    Last Post: 03-13-2008, 03:52 AM
  3. hex to binary,hex to decimal
    By groovy in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 02:14 AM
  4. Confused by expression.
    By Hulag in forum C Programming
    Replies: 3
    Last Post: 04-07-2005, 07:52 AM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM