解决方案 »

  1.   

    一般来说,程序员会尽量简化乘法运算,像你上面的算法,1024完全就可以提出来,运用数学来避免溢出。实在就是无法简化,就用ULONGLONG类型吧,如果ULONGLONG类型都无法解决,只能用大数运算了,那个就很费事了
      

  2.   

    __int64 lAdd;
    for(lAdd = 4i64*1024i64*1024i64;lAdd < 2i64*1024i64*1024i64*1024i64 ;lAdd += (4i64*1024i64))
    {if( lAdd<(__int64)iVal) lAdd += (1i64*1024i64*1024i64)-(4i64*1024i64);
    }
      

  3.   

    C++ Integer Constants
    Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.Syntaxinteger-constant :decimal-constant integer-suffixopt
    octal-constant integer-suffixopt
    hexadecimal-constant integer-suffixopt
    'c-char-sequence'decimal-constant :nonzero-digit
    decimal-constant digitoctal-constant :0
    octal-constant octal-digithexadecimal-constant :0x hexadecimal-digit
    0X hexadecimal-digit
    hexadecimal-constant hexadecimal-digitnonzero-digit : one of1 2 3 4 5 6 7 8 9octal-digit : one of0 1 2 3 4 5 6 7hexadecimal-digit : one of0 1 2 3 4 5 6 7 8 9
    a b c d e f
    A B C D E Finteger-suffix :unsigned-suffix long-suffixopt
    long-suffix unsigned-suffixoptunsigned-suffix : one ofu Ulong-suffix : one ofl L64-bit integer-suffix :i64To specify integer constants using octal or hexadecimal notation, use a prefix that denotes the base. To specify an integer constant of a given integral type, use a suffix that denotes the type.To specify a decimal constant, begin the specification with a nonzero digit. For example:int i = 157;   // Decimal constant
    int j = 0198;  // Not a decimal number; erroneous octal constant
    int k = 0365;  // Leading zero specifies octal constant, not decimalTo specify an octal constant, begin the specification with 0, followed by a sequence of digits in the range 0 through 7. The digits 8 and 9 are errors in specifying an octal constant. For example:int i = 0377;   // Octal constant
    int j = 0397;   // Error: 9 is not an octal digitTo specify a hexadecimal constant, begin the specification with 0x or 0X (the case of the “x” does not matter), followed by a sequence of digits in the range 0 through 9 and a (or A) through f (or F). Hexadecimal digits a (or A) through f (or F) represent values in the range 10 through 15. For example:int i = 0x3fff;   // Hexadecimal constant
    int j = 0X3FFF;   // Equal to iTo specify an unsigned type, use either the u or U suffix. To specify a long type, use either the l or L suffix. For example:unsigned uVal = 328u;             // Unsigned value
    long lVal = 0x7FFFFFL;            // Long value specified 
                                      //  as hex constant
    unsigned long ulVal = 0776745ul;  // Unsigned long value
      

  4.   

    溢出在 2*1024*1024*1024,这个超过32位的signed int范围了(尽管还在32位unsigned int范围内),改成1024u 应该就可以了。
      

  5.   

     DWORD lAdd;是4个字节,溢出了,改成8字节的long long或unsigned long long就行了
      

  6.   

    本帖最后由 VisualEleven 于 2014-08-28 10:51:39 编辑