Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Int size

gustavosserragustavosserra Member Posts: 201
Someone has told me that I can have a int of any length. For example: if need a 8 bytes number, I can make it!
My question is: "Is that possible?".
I was thinking abou using typedef... HELP!
GS

Comments

  • kuphrynkuphryn Member Posts: 266
    You could use a short data type. otherwise, you could use an int, but shift right 8. The int would look something like this in binary.

    00000000????????

    Kuphryn
  • SteveCSteveC Member Posts: 63
    : Someone has told me that I can have a int of any length. For example: if need a 8 bytes number, I can make it!
    : My question is: "Is that possible?".
    : I was thinking abou using typedef... HELP!
    : GS
    :
    Outside of the standard types you need an additional library like
    http://www.swox.com/gmp/

    You can have 8 byte numbers from the outset, if your processor is 64 bit.

  • Josh CodeJosh Code Member Posts: 675
    : Someone has told me that I can have a int of any length. For example: if need a 8 bytes number, I can make it!
    : My question is: "Is that possible?".
    : I was thinking abou using typedef... HELP!
    : GS
    :

    There are a set of integer types. Each type has a different size.

    For Example:

    char is 1 byte
    short is 2 bytes
    int is 4 bytes
    int64 is 8 bytes

    Using int64 types is usually quite inefficient. I mean that adding 2 int64 variables together will take the computer a lot longer than adding 2 int variables together. Making you own integer types would be even slower so I don't suggest it.
  • gustavosserragustavosserra Member Posts: 201
    : : Someone has told me that I can have a int of any length. For example: if need a 8 bytes number, I can make it!
    : : My question is: "Is that possible?".
    : : I was thinking abou using typedef... HELP!
    : : GS
    : :
    :
    : There are a set of integer types. Each type has a different size.
    :
    : For Example:
    :
    : char is 1 byte
    : short is 2 bytes
    : int is 4 bytes
    : int64 is 8 bytes
    :
    : Using int64 types is usually quite inefficient. I mean that adding 2 int64 variables together will take the computer a lot longer than adding 2 int variables together. Making you own integer types would be even slower so I don't suggest it.
    :
    Thanks everyone. But efficiency isnt the problem. I was just curious about this. The main problem was solve fatorial of high numbers.

  • Josh CodeJosh Code Member Posts: 675
    : : There are a set of integer types. Each type has a different size.
    : :
    : : For Example:
    : :
    : : char is 1 byte
    : : short is 2 bytes
    : : int is 4 bytes
    : : int64 is 8 bytes
    : :
    : : Using int64 types is usually quite inefficient. I mean that adding 2 int64 variables together will take the computer a lot longer than adding 2 int variables together. Making you own integer types would be even slower so I don't suggest it.
    : :
    : Thanks everyone. But efficiency isnt the problem. I was just curious about this. The main problem was solve fatorial of high numbers.
    :

    For factorials, you can try using int64 or maybe even float. You could try using a float like an integer. The range is much larger for a float because it uses exponencial information. The only drawback is that it may not be perfectly accurate.
  • abcabc Member Posts: 443
    : : Someone has told me that I can have a int of any length. For example: if need a 8 bytes number, I can make it!
    : : My question is: "Is that possible?".
    : : I was thinking abou using typedef... HELP!
    : : GS
    : :
    :
    : There are a set of integer types. Each type has a different size.
    :
    : For Example:
    :
    : char is 1 byte
    : short is 2 bytes
    : int is 4 bytes
    : int64 is 8 bytes
    the standard portable form would be int32_t and int64_t - you need stdint.h for that.(a 64bit machine has sizeof(int)=8). or, if your int is 4 bytes and your compiler supports it, use long long for 8 bytes.

  • gustavosserragustavosserra Member Posts: 201
    Ok, thanks a lot!. Ill see what fits best to my problem :).
  • Andre YoungAndre Young USAMember Posts: 0

    ___ < http://forcoder.org /> free ebooks and video tutorials about \ PHP, Go, C++, C, C#, Objective-C, PL/SQL, Assembly, Visual Basic .NET, R, Swift, Python, Visual Basic, JavaScript, Perl, Scratch, Delphi, Java, MATLAB, Ruby Ada, Transact-SQL, ABAP, LabVIEW, Apex, Rust, Scala, COBOL, Fortran, Erlang, SAS, F#, Hack, Crystal, VBScript, Julia, Scheme, Alice, Awk, Prolog, Logo, ML, Dart, Clojure, FoxPro, Bash, Kotlin, Lua, D, Lisp \ ___________

Sign In or Register to comment.