Thread: Multiplying two ULONG values?

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    25

    Multiplying two ULONG values?

    Morning,

    I have two ulong values blocks and LBA.

    Code:
    typedef struct _CAPACITY {
      ULONG LBA ;
      ULONG Blocks ;
    
    } CAPACITY, *PCAPACITY;
    And I can print them
    Code:
    printf("No of Logical block addresses        : %u  \n", wordSwap(receiveCapacity.LBA));
    printf("length of blocks in bytes                : %u   \n", wordSwap(receiveCapacity.Blocks));

    How does one multiply the values to get the total number of bytes on a disc? I've tried putting it into a few data types as I think the value "4,549,356,616" which is 4.23GB is too big for ULONG: Unsigned LONG. The range is 0 through 4294967295 decimal.

    It has to be declared as ULONG from the MMC6 specs I'm working from.
    wordswap reverses the byte order and it prints out fine.


    Code:
    ULONG Length_Bytes = wordSwap(recveiveCapacity.LBA) * wordSwap(recveiveCapacity.Blocks);
    printf("\nLenth Bytes = %u", Length_Bytes);
    = 254932992

    I've tried using ulong64 and ulonglong.

    Thanks!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need to cast at least one of your input operands to a 64-bit value (same principle as if you wanted to use floating point multiply with two integer operands), and then print as 64-bit in the printf statement.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    25
    Code:
     
    
    ULONG64 Length_Bytes = (ULONG64) wordSwap(recveiveCapacity.LBA) * wordSwap(recveiveCapacity.Blocks);
    printf("\nLenth Bytes = %u", Length_Bytes);

    and

    Code:
    ULONG64 Length_Bytes = (ULONG64) wordSwap(recveiveCapacity.LBA) * (ULONG64) wordSwap(recveiveCapacity.Blocks);
    printf("\nLenth Bytes = %u", Length_Bytes);
    = 3623878656


    It should be 8001767424. I think that's how you type cast anyway. The values print out correctly with the wordswap function. Ummm...

    Thanks again.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    and then print as 64-bit in the printf statement.
    You missed that part.

    In Windows, you'd use "%I64u".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    25
    *Air 5.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find Injected DLLs In A Process?
    By pobri19 in forum Windows Programming
    Replies: 35
    Last Post: 02-06-2010, 09:53 AM
  2. Help with ZwQueryDirectoryFile for my Driver.
    By taDo in forum Windows Programming
    Replies: 9
    Last Post: 11-27-2008, 08:54 AM
  3. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  4. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 05:01 PM