|
|
View previous topic :: View next topic |
Author |
Message |
Derek Guest
|
16-bits multiplication/adition problem? |
Posted: Mon Jan 13, 2003 2:07 pm |
|
|
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
|
Re: 16-bits multiplication/adition problem? |
Posted: Mon Jan 13, 2003 2:16 pm |
|
|
:=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? |
Posted: Mon Jan 13, 2003 3:24 pm |
|
|
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? |
Posted: Mon Jan 13, 2003 3:34 pm |
|
|
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? |
Posted: Mon Jan 13, 2003 3:52 pm |
|
|
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? |
Posted: Mon Jan 13, 2003 3:57 pm |
|
|
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 |
|
|
|
|
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
|