How do I get bigger vars? (bigger than 32 bit)
Results 1 to 10 of 10

Thread: How do I get bigger vars? (bigger than 32 bit)

  1. #1
    Member
    Join Date
    Sep 2003
    Posts
    42

    How do I get bigger vars? (bigger than 32 bit)

    Ok, so how do I get a number variable bigger than 32 bits? A long int only goes up that high. What is a bigger Variable? or how do I do that?
    In C/C++ I must add, I am wondering how to do it in C/C++.
    --------------------------------------------------------------------
    E, the modern pi.

  2. #2
    AntiOnline Senior Member souleman's Avatar
    Join Date
    Oct 2001
    Location
    Flint, MI
    Posts
    2,884
    push bits onto the stack and pop them off when you need them...

    ie.. for 64 bit number... push 32 bits...push next 32 bits... when you want to add, pop first 32 bits, do the add, save the overflow number, pop next 32 bits, finish the add, including the overflow number. (this is way over simplified, but you should get the idea).
    \"Ignorance is bliss....
    but only for your enemy\"
    -- souleman

  3. #3
    Senior Member
    Join Date
    Oct 2002
    Posts
    1,130
    I believe with most compilers, a double int is 64 bits, or 8 bytes.
    I remember learning souleman's method a while back, but can't remember how. Is there a way to do it without using assembly?
    Government is like fire - a handy servant, but a dangerous master - George Washington
    Government is not reason, it is not eloquence - it is force. - George Washington.

    Join the UnError community!

  4. #4
    Senior Member
    Join Date
    Jul 2002
    Posts
    315
    A long double will do the trick. Just say long double int and that should give you a number variable bigger than 32 bits.

    I hope that helps.

    Guidance...
    - The mind is too beautiful to waste...
    Cutty


  5. #5
    Member
    Join Date
    Sep 2003
    Posts
    42

    Ok

    Ok, i'm at school right now so I can't try that for myself but I will when I get home.
    --------------------------------------------------------------------
    E, the modern pi.

  6. #6
    AntiOnline Senior Member souleman's Avatar
    Join Date
    Oct 2001
    Location
    Flint, MI
    Posts
    2,884
    a double int will give you 64 bits, but that was just the example I used.. If you wanted to do like 128 bits or more, you have to use my method...

    You can do it in C using malloc() and ummm... I dont' remember the other commands, been a while.

    Check this... http://users.powernet.co.uk/eton/kandr2/krx400.html
    \"Ignorance is bliss....
    but only for your enemy\"
    -- souleman

  7. #7
    Member
    Join Date
    Sep 2002
    Posts
    77
    You could split the number into an array where each figure is held within a variable (along the lines of Binary Coded Decimal). This would be easy to do addition/subtraction with, as you could put each value into a seperate array, and then subtract each digit, i.e.


    Code:
      strInput is string
      strAction is string
      arBase  is array[1 to length of no1]
      arSubtractor is array[1 to length of subtraction number]
    
       Input strInput  
       Input strAction  // Read the two values
       
      For i = 0 to length of strInput - 1  // Loop to put the string in an array
         arBase[i + 1] = ASCII(strInput[length of strInput - i]) - 48  // Subtract 48 to convert it to a no, not an ascii key 
       // arBase stores the values in reverse order, easier
      next i  // End for loop, repeat for the no you want to subtract (i.e. strAction)
     
       // Next perform arithmetic
    
      For i = 1 to length of strAction
       arBase[i] = arBase[i] - arSubtractor[i]  // It's a bit more complicated than this, but you get the point, subtractor overflow from the next value in the array (I can't be bothered to show this - anyway you need _some_  of a challenge :) 
       next i  // End for loop
       
     End program
    That's the general idea of it, it'll work for just about any length of number (up to the limitation of nos within the array and limit of the string). PM me if you need any explanations or more help.
    \"Death is more universal than life; everyone dies but not everyone lives.\"
    A. Sachs

  8. #8
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    I don't know what "long double int" is, but

    AFAIK

    double or float is a floating point or double floating point value. It can hold values much larger than 2 x 10^9, but loses accuracy as a larger value is stored.

    Some compilers have an extra type "long long" that gives you one more than the normal "long" i.e. 64-bit even on a 32-bit platform.

    Lastly, if you happen to be on a 64-bit platform (Say, Alpha (Not Windows NT on Alpha, that is a 32bit hack iirc), ia64 or ppc64), then "int" will probably be 64 bits long anyway.

    Slarty

  9. #9
    Member
    Join Date
    Sep 2003
    Posts
    42

    Question O

    Ok, so how do propose I do a 4096 bit prime?
    I'm trying to do it for RSA, creating the keys.
    (While in C/C++)
    --------------------------------------------------------------------
    E, the modern pi.

  10. #10
    Senior Member
    Join Date
    Oct 2001
    Posts
    748
    Can't you just build your own memory space using a standard Win API? Like allocate and deallocate? You didn't specify which OS, but I know that is the easiest way to do it in VB, and most of those API's carry over to C++ and C#. You could get into trying to code your own algorithms to stack int's together to get the right variable size, but why recreate the wheel? There is plenty of great code out there to already do it. For unix you might need to snag an efficient module off of the web.

    Just google for memory management API, or memory management C++ 4096bytes. Something like that should return an answer for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •