We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0b2e25b commit f1d72c9Copy full SHA for f1d72c9
0x14-bit_manipulation/0-binary_to_uint.c
@@ -0,0 +1,29 @@
1
+#include "main.h"
2
+
3
+/**
4
+ * binary_to_uint - converts a binary number to an unsigned int.
5
+ * @b: pointer to a string containing a binary number
6
+ *
7
+ * Return: unsigned int with decimal value of binsry number, or 0 if error
8
+ */
9
+unsigned int binary_to_uint(const char *b)
10
+{
11
+ int i;
12
+ unsigned int num;
13
14
+ num = 0;
15
+ if (!b)
16
+ return (0);
17
+ for (i = 0; b[i] != '\0'; i++)
18
+ {
19
+ if (b[i] != '0' && b[i] != '1')
20
21
+ }
22
23
24
+ num <<= 1;
25
+ if (b[i] == '1')
26
+ num += 1;
27
28
+ return (num);
29
+}
0 commit comments