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

16-bits multiplication/adition problem?

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







16-bits multiplication/adition problem?
PostPosted: Mon Jan 13, 2003 2:07 pm     Reply with quote

I have a quick question in regards to multiplication. I don't seem to be able to multiply/add anything greater than 8bits.

I have the PCH compiler version 3.086 for a PIC16F877.

Here's the code.

int16 temp_window;

temp_window = 1*256;
printf( "\%4x", temp_window ); //displays 0000
temp_window = temp_window + 0xbc;
printf( "\%4x", temp_window ); //displays 00bc

or

temp_window = temp_window + 0xbc;
printf( "\%4x", temp_window ); //displays 00bc
temp_window = temp_window + 0xbc;
printf( "\%4x", temp_window ); //displays 0078

how come the 16 bit variable is truncating???

please help...
___________________________
This message was ported from CCS's old forum
Original Post ID: 10659
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: 16-bits multiplication/adition problem?
PostPosted: Mon Jan 13, 2003 2:16 pm     Reply with quote

:=I have a quick question in regards to multiplication. I don't seem to be able to multiply/add anything greater than 8bits.
:=
:=I have the PCH compiler version 3.086 for a PIC16F877.

You mean the PCM compiler.

:=
:=temp_window = 1*256;
:=printf( "\%4x", temp_window );

In CCS, you have to use "lx" for a 16-bit or 32-bit number.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10660
Derek
Guest







Re: 16-bits multiplication/adition problem?
PostPosted: Mon Jan 13, 2003 3:24 pm     Reply with quote

okay, I tried another test.


int16 temp_window;
temp_window = 0x1234;
printf("\%4x", temp_window);

the result that is printed out is 0034

Why's that??? Please help

:=I have a quick question in regards to multiplication. I don't seem to be able to multiply/add anything greater than 8bits.
:=
:=I have the PCH compiler version 3.086 for a PIC16F877.
:=
:=Here's the code.
:=
:=int16 temp_window;
:=
:=temp_window = 1*256;
:=printf( "\%4x", temp_window ); //displays 0000
:=temp_window = temp_window + 0xbc;
:=printf( "\%4x", temp_window ); //displays 00bc
:=
:=or
:=
:=temp_window = temp_window + 0xbc;
:=printf( "\%4x", temp_window ); //displays 00bc
:=temp_window = temp_window + 0xbc;
:=printf( "\%4x", temp_window ); //displays 0078
:=
:=how come the 16 bit variable is truncating???
:=
:=please help...
___________________________
This message was ported from CCS's old forum
Original Post ID: 10663
Dave Yeatman
Guest







Re: 16-bits multiplication/adition problem?
PostPosted: Mon Jan 13, 2003 3:34 pm     Reply with quote

As PCM said "\%4x" is for 8 bit. Try \%4lx".... You are truncating to the two least significant hex digits and adding two leading zeros since you specify four decimal places.... This is not ANSI standard C.


:=okay, I tried another test.
:=
:=
:=int16 temp_window;
:=temp_window = 0x1234;
:=printf("\%4x", temp_window);
:=
:=the result that is printed out is 0034
:=
:=Why's that??? Please help
:=
:=:=I have a quick question in regards to multiplication. I don't seem to be able to multiply/add anything greater than 8bits.
:=:=
:=:=I have the PCH compiler version 3.086 for a PIC16F877.
:=:=
:=:=Here's the code.
:=:=
:=:=int16 temp_window;
:=:=
:=:=temp_window = 1*256;
:=:=printf( "\%4x", temp_window ); //displays 0000
:=:=temp_window = temp_window + 0xbc;
:=:=printf( "\%4x", temp_window ); //displays 00bc
:=:=
:=:=or
:=:=
:=:=temp_window = temp_window + 0xbc;
:=:=printf( "\%4x", temp_window ); //displays 00bc
:=:=temp_window = temp_window + 0xbc;
:=:=printf( "\%4x", temp_window ); //displays 0078
:=:=
:=:=how come the 16 bit variable is truncating???
:=:=
:=:=please help...
___________________________
This message was ported from CCS's old forum
Original Post ID: 10664
Derek
Guest







Re: 16-bits multiplication/adition problem?
PostPosted: Mon Jan 13, 2003 3:52 pm     Reply with quote

Yes, I mean PCM. I though the L portion of \%Lx is the length I would like to specify; as in the example.

\%4X 0012 00FE

:=:=I have a quick question in regards to multiplication. I don't seem to be able to multiply/add anything greater than 8bits.
:=:=
:=:=I have the PCH compiler version 3.086 for a PIC16F877.
:=
:=You mean the PCM compiler.
:=
:=:=
:=:=temp_window = 1*256;
:=:=printf( "\%4x", temp_window );
:=
:=In CCS, you have to use "lx" for a 16-bit or 32-bit number.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10665
Derek
Guest







Re: 16-bits multiplication/adition problem?
PostPosted: Mon Jan 13, 2003 3:57 pm     Reply with quote

Oh, I got it to work. Thanks guys. All this time, I thought it was some sort of type casting problem and it drove me nuts.

Derek

:=As PCM said "\%4x" is for 8 bit. Try \%4lx".... You are truncating to the two least significant hex digits and adding two leading zeros since you specify four decimal places.... This is not ANSI standard C.
:=
:=
:=:=okay, I tried another test.
:=:=
:=:=
:=:=int16 temp_window;
:=:=temp_window = 0x1234;
:=:=printf("\%4x", temp_window);
:=:=
:=:=the result that is printed out is 0034
:=:=
:=:=Why's that??? Please help
:=:=
:=:=:=I have a quick question in regards to multiplication. I don't seem to be able to multiply/add anything greater than 8bits.
:=:=:=
:=:=:=I have the PCH compiler version 3.086 for a PIC16F877.
:=:=:=
:=:=:=Here's the code.
:=:=:=
:=:=:=int16 temp_window;
:=:=:=
:=:=:=temp_window = 1*256;
:=:=:=printf( "\%4x", temp_window ); //displays 0000
:=:=:=temp_window = temp_window + 0xbc;
:=:=:=printf( "\%4x", temp_window ); //displays 00bc
:=:=:=
:=:=:=or
:=:=:=
:=:=:=temp_window = temp_window + 0xbc;
:=:=:=printf( "\%4x", temp_window ); //displays 00bc
:=:=:=temp_window = temp_window + 0xbc;
:=:=:=printf( "\%4x", temp_window ); //displays 0078
:=:=:=
:=:=:=how come the 16 bit variable is truncating???
:=:=:=
:=:=:=please help...
___________________________
This message was ported from CCS's old forum
Original Post ID: 10666
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