Function that toggle LED on and off
This question already has an answer here:
Certainly. What you want is to perform a logical XOR with 00000001
(this is called a mask):
MASK INPUT OUTPUT
00000001 XOR 00000000 = 00000001
00000001 XOR 00000001 = 00000000
This also makes it possible to toggle more than one bit, eg, if your mask were 00001001
:
MASK INPUT OUTPUT
00001001 XOR 00000000 = 00001001
00001001 XOR 00001001 = 00000000
00001001 XOR 00001000 = 00000001
00001001 XOR 00000001 = 00001000
链接地址: http://www.djcxy.com/p/28810.html
上一篇: C ++删除第一个位
下一篇: 打开和关闭LED的功能