![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
iseron
Joined: 21 Feb 2004 Posts: 12 Location: Santiago - Chile
|
multiplication: result=32 bits , original numbers = 16 bit |
Posted: Sun Mar 07, 2004 12:37 am |
|
|
Hi i need to obtain a 32 bit number for the size of an archive in FAT12-FAt16 root directory standard. (the standar said that the size always its a 32 bits number size in little endian form)
My purpose is to do an archive to fill all the space in a CompactFlash and i have to put the size in every case of CF size.
The variables:
unsigned long int sectors_cluster; // 16 bits?
unsigned long int fat_copies; // 16 bits?
unsigned long int sectores_por_fat; // 16 bits?
The function:
void directorio_raiz (int32 tamano) //tamano is "size" in spanish
The failed operation(return 16 bits instead of 32 bits):
directorio_raiz ((int32)512*lba_tot-512-(int32)512*fat_copies*sectores_por_fat-(int32)512*32);
What can i do?
I was thinking about to do an ATOI32( text) for reach my objective, but how to transform the "number" in "text"? same problem..
Ignacio. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: multiplication: result=32 bits , original numbers = 16 b |
Posted: Sun Mar 07, 2004 4:32 am |
|
|
iseron wrote: | Hi i need to obtain a 32 bit number for the size of an archive in FAT12-FAt16 root directory standard. (the standar said that the size always its a 32 bits number size in little endian form)
My purpose is to do an archive to fill all the space in a CompactFlash and i have to put the size in every case of CF size.
The variables:
unsigned long int sectors_cluster; // 16 bits?
unsigned long int fat_copies; // 16 bits?
unsigned long int sectores_por_fat; // 16 bits?
The function:
void directorio_raiz (int32 tamano) //tamano is "size" in spanish
The failed operation(return 16 bits instead of 32 bits):
directorio_raiz ((int32)512*lba_tot-512-(int32)512*fat_copies*sectores_por_fat-(int32)512*32);
What can i do?
I was thinking about to do an ATOI32( text) for reach my objective, but how to transform the "number" in "text"? same problem..
Ignacio. |
The first thing is that you say that the operation 'returned' a 16bit value, yet what you show has the operation returing nothing (void). I presume you mean that the value that arrived in the function is 16bit?. It is not the constants that you need to 'cast' to int32 (as shown), but the variables. So, something like:
directorio_raiz (512l*(int32)lba_tot-512l-512l*(int32)fat_copies*(int32)sectores_por_fat-512l*32l);
A constant will by default be a 'long', if it is greater than 255, though you can also 'force' this by adding an 'l' to the value.
Are you also sure of your arithmetic 'order'. I'd be looking at adding some brackets to ensure that the parts of the conversion are dealt with in the correct relation. As shown the arithmetic does not look right. For instance, you start by multiplying lbs_tot*512, and then subtracting 512 from this total. I'd simply multiply (lba_tot-1)*512. It is the 'end' of the statement that looks really odd though. Remember that multiplication has priority over subtraction, so the tail of the statement evaluates to 'sectores_por_fat' minus (512*32). I suspect this should be typed as:
((int32)sectores_por_fat - 512l)*32l
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
iseron
Joined: 21 Feb 2004 Posts: 12 Location: Santiago - Chile
|
|
Posted: Sun Mar 07, 2004 1:12 pm |
|
|
Let me explain better my problem.
1) the void function need a 32 bit entry, then write the size of this 32 bits onto the compact flash. But with the multiplication showed, i can't obtain the 32 bits value only a max of 65535 or 16 bits number FFFFh.
I have inside the void this "printf("\n\rtamaņo grabado = %ld", tamano);" then i know the number introduced.
2) My way to write the operation, its because i think that the compiler "don't see" the parentesis of a big operation. My first test was directorio_raiz (512*(lba_tot-1-fat_copies*sectores_por_fat-32)); but returned a number like ~3000 or near to that. After change the way and puting all in a plain way i obtained a 16 bits. like a ~62000 .. don't remember.
Now i will use de "|" operator but in the manual appear like a bitwise inclusive or operator.
Other ideas for multipliying?
thanks. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sun Mar 07, 2004 2:59 pm |
|
|
iseron wrote: | Let me explain better my problem.
1) the void function need a 32 bit entry, then write the size of this 32 bits onto the compact flash. But with the multiplication showed, i can't obtain the 32 bits value only a max of 65535 or 16 bits number FFFFh.
I have inside the void this "printf("\n\rtamaņo grabado = %ld", tamano);" then i know the number introduced.
2) My way to write the operation, its because i think that the compiler "don't see" the parentesis of a big operation. My first test was directorio_raiz (512*(lba_tot-1-fat_copies*sectores_por_fat-32)); but returned a number like ~3000 or near to that. After change the way and puting all in a plain way i obtained a 16 bits. like a ~62000 .. don't remember.
Now i will use de "|" operator but in the manual appear like a bitwise inclusive or operator.
Other ideas for multipliying?
thanks. |
The operator for forcing a constant to long, is 'l' (lower case L), not the 'pipe' symbol (for OR).
As shown, the maths would have been done in 16bit, and hence the return around 3000. Re-type your original statement, and cast each of the variables to int32.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|