-1_modifyBit_return_mask

Dependencies:   mbed

Revision:
1:cb2dac24de1b
Parent:
0:d87fdef72565
Child:
2:11a1722e34a4
--- a/main.cpp	Mon Jan 13 17:24:08 2020 +0000
+++ b/main.cpp	Mon Jan 13 17:30:20 2020 +0000
@@ -26,3 +26,9 @@
      printb(modifyBit(INIT,3,1));
      wait(0.1);
 }
+int modifyBit(int x,unsigned char position, bool State){
+    int mask=1<<position;
+    int state=int(State);
+    return (x & ~mask) | ((state << position) & mask);
+    
+    }