Thread: Storing large integers....why doesn't this work?

  1. #1
    Unregistered
    Guest

    Storing large integers....why doesn't this work?

    Hi
    please excuse this dumb question:

    I'm trying to store the product of 2 unsigned integers into a unsigned long integer:

    unsigned int a; //a=355
    unsigned int b; //b=336
    unsigned long int array; // array = b*a;

    array = (unsigned long int) b*a;
    printf("%u", array);



    The result I get in the print out is array=54752 (D5E0 in hex, where I should be getting 1D5E0 or 120288 in decimal).

    Anybody know what's going on?

  2. #2
    Ethereal Raccoon Procyon's Avatar
    Join Date
    Aug 2001
    Posts
    189
    Use %lu instead of %u to output longs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-24-2005, 11:26 AM
  2. Representing a Large Integer with an Array
    By random_accident in forum C++ Programming
    Replies: 3
    Last Post: 03-03-2005, 12:23 PM
  3. infinite looping when 2 large integers divide
    By Horse22 in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2005, 11:25 AM
  4. Scanning integers from a file:
    By xarmenx in forum C Programming
    Replies: 6
    Last Post: 11-29-2004, 04:57 PM
  5. Messing with Large Integers
    By johnnie2 in forum Windows Programming
    Replies: 3
    Last Post: 11-16-2002, 01:22 PM