Browse code

Added binary to decimal converter; updated README accordingly.

haywalk authored on 19/09/2019 01:26:21
Showing 3 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+'''
2
+Binary interpreter
3
+Hayden Walker, 18 September
4
+'''
5
+
6
+nums = input().split() # Split the string into individual values
7
+output = str() # Create the output string
8
+
9
+for byte in nums:
10
+	byte = byte[::-1] # Reverse the byte so that its indexes correspond to powers
11
+	out, pos = 0, 0 # Counters for the byte's value, as well as what byte is being counted
12
+
13
+	for bit in byte:
14
+		if int(bit): # 1 = True
15
+			out += 2 ** pos
16
+		pos += 1
17
+
18
+	output += str(out) + " " # Concatenate the value onto the output string
19
+
20
+print(output)
... ...
@@ -29,6 +29,17 @@ Aquarium (19 August) [Requires Pygame]
29 29
 
30 30
     A simple aquarium. A random number of fish are spawned, each being an instance of the Fish class. Each is randomly assigned one of four breeds, and each has a randomly assigned speed. The fish will change directions when they come in contact with the screen's edge. Furthermore, each 50 millisecond cycle, each fish has a 1% chance (for each axis) of changing direction on its own, regardless of its position.
31 31
 ------------------------------------------------------------------------------------------------------------
32
+Binary to Decimal Converter (18 August)
33
+    *String slicing
34
+        *Reversing
35
+        *Concatenation
36
+    *Iterables
37
+    *Conditionals
38
+    *Math operators
39
+        *Powers
40
+    
41
+    A simple binary to decimal converter; will accept an arbitrtary amount of bytes of arbitrary lengths.
42
+------------------------------------------------------------------------------------------------------------
32 43
 Caesar Cypher (25 July)
33 44
     *Iterables
34 45
     *Conditionals
35 46
Binary files a/README.pdf and b/README.pdf differ