Compare commits
6 Commits
acff092e30
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46388bc302 | ||
|
|
98f616b5a2 | ||
|
|
8b2f9a291a | ||
|
|
0e4cd2427a | ||
|
|
8db5c9c7d0 | ||
|
|
1f2ed35c44 |
@@ -8,10 +8,10 @@ https://www.pgonline.co.uk/resources/computer-science/a-level-ocr/ocr-a-level-te
|
||||
- Conversions between bases (integers)<br/>
|
||||
- Binary addition<br/>
|
||||
- Floating point binary to denery conversion<br/>
|
||||
- Two's complement<br/>
|
||||
- Sign and magnitude<br/>
|
||||
|
||||
# TODO
|
||||
- Two's complement<br/>
|
||||
- Sign and magnitude<br/>
|
||||
- Complex binary* <br/>
|
||||
|
||||
# Why the fuck is this a thing?
|
||||
|
||||
1
bases-game.js
Normal file
1
bases-game.js
Normal file
@@ -0,0 +1 @@
|
||||
Math.random
|
||||
@@ -5,7 +5,7 @@ answered = 0
|
||||
def correct():
|
||||
global score
|
||||
score+=1
|
||||
print("Correct!")
|
||||
print("\nCorrect!")
|
||||
while True:
|
||||
'''
|
||||
Conversion ----- 2 -> 10
|
||||
@@ -17,10 +17,73 @@ while True:
|
||||
|
||||
Binary Addition
|
||||
Floating point binary
|
||||
Twos compliment, Sign & Magnitude, Complex binary
|
||||
Twos compliment,
|
||||
Sign & Magnitude,
|
||||
'''
|
||||
type_int = random.randint(0,2)
|
||||
type_int = random.randint(0,4)
|
||||
|
||||
if type_int == 4:
|
||||
start_base = random.randint(0,1)
|
||||
number_int = random.randint(0,128)
|
||||
number_bin = format(number_int, '#010b')[2:]
|
||||
if random.randint(0,1) == 1: # 50/50 chance of being negative
|
||||
number_int = 0 - number_int
|
||||
number_bin = '1' + number_bin[1:]
|
||||
if start_base == 0: # Binary -> Denery
|
||||
print("\nWhat is this Sign and Magnitude base 2 number in base 10?\n")
|
||||
print(number_bin)
|
||||
print("")
|
||||
print("-")
|
||||
print("|100")
|
||||
print("||10")
|
||||
print("|||1")
|
||||
print("||||")
|
||||
print("VVVV")
|
||||
answer = str(int(number_int))
|
||||
elif start_base == 1: # Denery -> Binary
|
||||
print("\nWhat is this base 10 number in Sign and Magnitude base 2?\n")
|
||||
print(number_int)
|
||||
print("")
|
||||
print("-")
|
||||
print("|64")
|
||||
print("||32")
|
||||
print("|||16")
|
||||
print("||||8421")
|
||||
print("||||||||")
|
||||
print("VVVVVVVV")
|
||||
answer = str(int(number_bin))
|
||||
attempt = input()
|
||||
if int(attempt) == int(answer):
|
||||
correct()
|
||||
else:
|
||||
print(f"No, the answer was {answer}")
|
||||
if type_int == 3:
|
||||
start_base = random.randint(0,1)
|
||||
positive_int = random.randint(0,127)
|
||||
negative_int = 0 - positive_int
|
||||
positive_bin = format(positive_int, '#010b')[2:]
|
||||
negative_bin = ""
|
||||
for x in positive_bin:
|
||||
if x == "0":
|
||||
negative_bin += "1"
|
||||
else:
|
||||
negative_bin += "0"
|
||||
|
||||
negative_bin = bin(int(negative_bin,2) + 1)[2:]
|
||||
if (start_base == 0): # Binary -> Denery
|
||||
print("\nWhat does this two's compliment number represent in base 10?\n")
|
||||
print(negative_bin)
|
||||
answer = str(negative_int)
|
||||
elif (start_base == 1): # Denery -> Binary
|
||||
print("\nWhat does this negative number represent in base 2 (two's compliment)\n")
|
||||
print(negative_int)
|
||||
answer = str(negative_bin)
|
||||
|
||||
attempt = input()
|
||||
if attempt == answer:
|
||||
correct()
|
||||
else:
|
||||
print(f"No, the answer was {answer}")
|
||||
if type_int == 2:
|
||||
print("What is this binary floating point number in denery?\n")
|
||||
int_length = random.randint(0,7)
|
||||
@@ -41,7 +104,7 @@ while True:
|
||||
else:
|
||||
print(f"No, the answer was {answer}")
|
||||
if type_int == 1:
|
||||
answer_in_bin_or_den = random.randint(0,1)
|
||||
answer_in_bin_or_den = random.randint(0,0)
|
||||
if answer_in_bin_or_den == 1:
|
||||
print("Answer in Base 10\n")
|
||||
if answer_in_bin_or_den == 0:
|
||||
|
||||
Reference in New Issue
Block a user