df

Dependencies:   mbed

Fork of APP1 by Team APP

Revision:
12:1c341b119b23
Parent:
9:12519f9dd3cd
Child:
13:bb9669053eb3
--- a/Utility.cpp	Sun Jan 15 18:57:53 2017 +0000
+++ b/Utility.cpp	Sun Jan 15 19:46:10 2017 +0000
@@ -21,4 +21,14 @@
         const double angle_degree = angle_radian * 180.0 / PI;
         return wrap_angle(angle_degree);
     }
+    
+    int update_bit(const int previous_4_bytes, const int position, const bool new_bit_value)
+    {
+        const int all_zero_but_one_at_position = 0x1 << position;
+        const int all_one_but_zero_at_position = ~all_zero_but_one_at_position;
+        const int all_zero_but_new_bit_value_at_position = new_bit_value << position;
+        const int all_unchanged_but_zero_at_position = previous_4_bytes & all_one_but_zero_at_position;
+        const int all_unchanged_but_new_bit_value_at_position = all_unchanged_but_zero_at_position | all_zero_but_new_bit_value_at_position;
+        return all_unchanged_but_new_bit_value_at_position;
+    }
 }
\ No newline at end of file