Calculation returning wrong value
Posted: Sat Feb 21, 2009 11:30 pm
Hi guys,
I'm attempting to calculate the partition size from the MBR record of my drive. I have parsed all the information and even built a proper 32-bit value of the number of blocks in the partition. I am then multiplying the number of blocks by 512 bytes.
0x12a18a82 hex is 312576642 decimal. I calculate that by 512 using the calculator and get 160,039,240,704 which is correct. I have a 160GB partition. However when I try to calculate this into a long long (8 byte size in Windows) using C and get 1,125,450,752. Any reason why it is doing this?
This outputs:
Number of blocks (hex): 0x12a18a82
Number of blocks (dec): 312576642
Partition size: 1125450752
Any suggestions?
I'm attempting to calculate the partition size from the MBR record of my drive. I have parsed all the information and even built a proper 32-bit value of the number of blocks in the partition. I am then multiplying the number of blocks by 512 bytes.
0x12a18a82 hex is 312576642 decimal. I calculate that by 512 using the calculator and get 160,039,240,704 which is correct. I have a 160GB partition. However when I try to calculate this into a long long (8 byte size in Windows) using C and get 1,125,450,752. Any reason why it is doing this?
Code: Select all
long long tempPartSize = 0;
unsigned int numBlocks = 0;
/* Calculate partition size from number of blocks */
numBlocks = Concat32BitLE(partBuffer[12], partBuffer[13], partBuffer[14], partBuffer[15]);
printf("Number of blocks (hex): 0x%08x\n", numBlocks);
printf("Number of blocks (dec): %d\n", numBlocks);
tempPartSize = (numBlocks * 512);
printf("Partition size: %lld\n", tempPartSize);
Number of blocks (hex): 0x12a18a82
Number of blocks (dec): 312576642
Partition size: 1125450752
Any suggestions?