Tintin's blog

By Tintin, 12 years ago, In English

Hi, if the upper range of unsigned __int64 is 2^64-1 then how can I get any number modulo by 2^64? Thanks.

  • Vote: I like it
  • -16
  • Vote: I do not like it

»
12 years ago, # |
  Vote: I like it 0 Vote: I do not like it

What do you mean saying "how can I get any number modulo by 2^64?"? what's "any" number? Give an example, please.

  • »
    »
    12 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    suppose, (2^63+2^63)%2^64= ? How can I get this answer?

    • »
      »
      »
      12 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      unsigned long long a = 1ULL << 63;
      unsigned long long b = 1ULL << 63;
      cout << a + b;
      
    • »
      »
      »
      12 years ago, # ^ |
      Rev. 2   Vote: I like it +8 Vote: I do not like it

      If you use unsigned long long, numbers are automatically by modulo 264, and you dont need do anything.

      • »
        »
        »
        »
        12 years ago, # ^ |
          Vote: I like it +2 Vote: I do not like it

        Thanks dalex and notime.sea. I get it

»
12 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Modulo 2^64? It's easy. Just use unsigned long long and... nothing more!