aboutsummaryrefslogtreecommitdiffstats
path: root/test/gourdinl/c/msb_pos.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/gourdinl/c/msb_pos.c')
-rw-r--r--test/gourdinl/c/msb_pos.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/gourdinl/c/msb_pos.c b/test/gourdinl/c/msb_pos.c
new file mode 100644
index 00000000..f2e7fe09
--- /dev/null
+++ b/test/gourdinl/c/msb_pos.c
@@ -0,0 +1,20 @@
+/* Function to find the MSB bit position */
+int main(int n)
+{
+ int i = 0, bit;
+ while (i < 32)
+ {
+ bit = n & 0x80000000;
+ if (bit == -0x80000000)
+ {
+ bit = 1;
+ }
+
+ if (bit == 1)
+ break;
+
+ n = n << 1;
+ i++;
+ }
+ return i;
+}