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

BITWISE & not working...

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



Joined: 27 Aug 2011
Posts: 16
Location: Baltimore, MD

View user's profile Send private message

BITWISE & not working...
PostPosted: Tue Jan 16, 2018 6:57 pm     Reply with quote

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: 20337

View user's profile Send private message

PostPosted: Tue Jan 16, 2018 7:24 pm     Reply with quote

The first test gives 0x1000, which is accurate:
Quote:
A = 1000

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.
Quote:
A = 1000

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);           
}
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