← pynet

exercise2

832d25a231d21dc34aa5f3d8e9ee206763f48413 · ovidiucs · Sep 13, 2015 11:32

+15 · 1 file changed

  • course_2/ex2_binary_convert.py +15 −0
diff --git a/course_2/ex2_binary_convert.py b/course_2/ex2_binary_convert.py
new file mode 100644
index 0000000..e97f025
--- /dev/null
+++ b/course_2/ex2_binary_convert.py
@@ -0,0 +1,15 @@
+
+print "Input the network"
+octets = raw_input('> ')
+s      = octets.split('.')
+
+first_octet   = int(s[0])
+second_octet  = int(s[1])
+third_octet   = int(s[2])
+fourth_octet  = int(s[3])
+
+print "%0s %20s %20s %20s" % \
+              ("first_octet", "second_octet", "third_octet", "fourth_octet")
+              print "%0s %20s %20s %20s" % \
+              ('{0:08b}'.format(first_octet),'{0:08b}'.format(second_octet),
+               '{0:08b}'.format(third_octet),'{0:08b}'.format(fourth_octet))