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

This is a discussion on Storing large integers....why doesn't this work? within the C Programming forums, part of the General Programming Boards category; Hi please excuse this dumb question: I'm trying to store the product of 2 unsigned integers into a unsigned long ...

  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, 11:23 AM
  3. infinite looping when 2 large integers divide
    By Horse22 in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2005, 10:25 AM
  4. Scanning integers from a file:
    By xarmenx in forum C Programming
    Replies: 6
    Last Post: 11-29-2004, 03:57 PM
  5. Messing with Large Integers
    By johnnie2 in forum Windows Programming
    Replies: 3
    Last Post: 11-16-2002, 12:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21