Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1018813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:54:53+00:00 2026-05-16T10:54:53+00:00

I want to multiply long numbers which are given in a 2^32 basis. I

  • 0

I want to multiply long numbers which are given in a 2^32 basis. I already thought of an nice algorithm to do that, but unfortunatly I’m stuck. The situation I’m stuck at, is how I do multiply two long ints and represent it on the 2^32 basis.

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
typedef unsigned int uint32;
typedef unsigned long long uint64;
int main(int argc, char* argv[] )
{

  uint64 a = (uint64)ULONG_MAX;
  printf("%llu\n", a);
  uint64 b = (uint64)ULONG_MAX;  
  printf("%llu\n", b);  
  uint64 c = (uint64)(a*b);

  printf("%llu\n", c);  // prints 1. that would be to lower 32 bits of the results. the upper half is 0xFFFFFFFE

  printf("%llu\n", ULLONG_MAX);
  system("pause");
}

Why is ULLONG_MAX the same as ULONG_MAX ? According to http://en.wikipedia.org/wiki/Limits.h#Member_constants it should be 18,446,744,073,709,551,615 I

As you can see from my comments, I want the result of the the multiplikation in the two uint32.
The lowerhalf would be 0x1 and the upper half 0xFFFFFFFE. How do I get these values?

(I found this question on SO, but it’s not helpful in my situation because the answers given ar similiar to my ideas: Multiplying two long long ints C)

Edit:
My system is Windows XP 32 Bit. I’m using gcc 3.4.2 (mingw-special)

The output I do get while running the code:

4294967295
4294967295
1
4294967295

Edit2:

  printf("%i\n", sizeof(unsigned long));
  printf("%i\n", sizeof(unsigned long long)); 

returns

4
8

Edit 3:
Thanks to Petesh I was able to find the solution:

  printf("%lu\n", c & 0xFFFFFFFF);
  printf("%lu\n", (c >> 32));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:54:53+00:00Added an answer on May 16, 2026 at 10:54 am

    The hint is in the system(“pause”) – you’re on windows? Printing a long long using the Microsoft visual c runtime requires using ‘%I64u’ (that’s a capital i).

    This is based on SO question How do you printf an unsigned long long int(the format specifier for unsigned long long int)?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Under what circumstances might you want to use multiple indirection (that is, a chain
I want to create a c# application with multiple windows that are all transparent
I want to match a block of code multiple times in a file but
I want to merge multiple rss feeds into a single feed, removing any duplicates.
I want to insert multiple invisible watermarks into my JPEG pictures through C# code.
I want to embed multiple audio to my site. I want the file to
First of all, I am a complete Java NOOB. I want to handle multiple
I want to add same field to multiple tables. Can I do this with
We have multiple vb projects.We want to put error handlers in all functions, and
I want to use Google spreadsheets to store data online so multiple people can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.