CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

multiplication: result=32 bits , original numbers = 16 bit

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
iseron



Joined: 21 Feb 2004
Posts: 12
Location: Santiago - Chile

View user's profile Send private message

multiplication: result=32 bits , original numbers = 16 bit
PostPosted: Sun Mar 07, 2004 12:37 am     Reply with quote

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.
Ttelmah
Guest







Re: multiplication: result=32 bits , original numbers = 16 b
PostPosted: Sun Mar 07, 2004 4:32 am     Reply with quote

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
iseron



Joined: 21 Feb 2004
Posts: 12
Location: Santiago - Chile

View user's profile Send private message

PostPosted: Sun Mar 07, 2004 1:12 pm     Reply with quote

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.
Ttelmah
Guest







PostPosted: Sun Mar 07, 2004 2:59 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 07, 2004 4:27 pm     Reply with quote

Quote:
Now i will use de "|" operator but in the manual appear like a bitwise inclusive or operator.

Quote:
The operator for forcing a constant to long, is 'l' (lower case L), not the 'pipe' symbol (for OR).


I don't want to get you angry at me, but, Smile
MS recommends using upper-case L to avoid this type of confusion.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/eleme_13.asp
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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