|
|
View previous topic :: View next topic |
Author |
Message |
uslimey
Joined: 27 Aug 2011 Posts: 22 Location: Baltimore, MD
|
BITWISE & not working... |
Posted: Tue Jan 16, 2018 6:57 pm |
|
|
I am trying to do a bitwise AND on two uInt16 numbers.
unsigned int16 A = 0b0001000000000000;
unsigned int16 B = 0b0001010101010101;
A &= B; // the result (A) should be 0b0001000000000000, instead the result is 0???
This makes no sense... Try it again...
unsigned int16 A = 0b0001000000000000;
unsigned int16 B = 0b0001010101010101;
unsigned int16 C = A & B; // the result (C) should be 0b0001000000000000, instead the result is 0???
This is with a PIC16F722A and version 5.075 of the compiler...
Any suggestions? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 16, 2018 7:24 pm |
|
|
The first test gives 0x1000, which is accurate:
First test program:
Code: |
#include <16F722A.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
//======================
void main()
{
unsigned int16 A = 0b0001000000000000;
unsigned int16 B = 0b0001010101010101;
A &= B;
printf("A = %lx \r", A);
while(TRUE);
}
|
The 2nd test also gives 0x1000, which is accurate.
So I think you may have a problem with your binary display routine.
These tests were both done in MPLAB v8.92 simulator with CCS v5.075.
2nd test program.
Code: | #include <16F722A.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
//======================
void main()
{
unsigned int16 A = 0b0001000000000000;
unsigned int16 B = 0b0001010101010101;
unsigned int16 C = A & B;
printf("C = %lx \r", C);
while(TRUE);
} |
|
|
|
|
|
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
|