]> hackdaworld.org Git - my-code/beginners.git/commitdiff
added string2bin
authorhackbard <hackbard>
Thu, 13 Mar 2003 13:42:32 +0000 (13:42 +0000)
committerhackbard <hackbard>
Thu, 13 Mar 2003 13:42:32 +0000 (13:42 +0000)
string2bin.c [new file with mode: 0644]

diff --git a/string2bin.c b/string2bin.c
new file mode 100644 (file)
index 0000000..3d8f928
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+ unsigned char *s=argv[1];
+ int i,j;
+ for(j=0;j<strlen(s);j++) {
+  for(i=7;i>=0;i--) {
+    printf("%s%d%s",i==7?"|":"",
+                  s[j]&(1<<i)?1:0,
+                  i==0?"|\n":"|");
+  }
+ }
+return 23;
+}