I read port B value=input_b();
I need only LSB-bit in B-port.
How i can work AND-operator?
This: value=input_b()&0x0f
or value=input_b()&&0x0f
or how???
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
Posted: Mon Nov 19, 2007 8:35 am
The very best way to find out is to write a short test program using both and look at the assembly code generated.
The second best way is to look in a C primer book and read the differences between Logical AND and Bitwise AND.
The least best way is to ask here and have someone you don't know simply tell you that you should use value=input_b()&0x0f for the least significant nibble or value=input_b()&0x01 for the least significant bit. _________________ The search for better is endless. Instead simply find very good and get the job done.
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
Posted: Mon Nov 19, 2007 8:45 am
I totally agree with SherpaDoug and would like to insert a third option, i.e. before asking on this forum:
3) Read the manual and study all available commands. Just so you know which commands and helper functions exist (you might have stumbled upon the bit_test() function).
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