Compare commits
No commits in common. "98f616b5a296ed4267383ff2b6c22431f0b77f96" and "0e4cd2427a6357d7c5dbbf367a3171ea84ac0fc4" have entirely different histories.
98f616b5a2
...
0e4cd2427a
@ -9,9 +9,9 @@ https://www.pgonline.co.uk/resources/computer-science/a-level-ocr/ocr-a-level-te
|
||||
- Binary addition<br/>
|
||||
- Floating point binary to denery conversion<br/>
|
||||
- Two's complement<br/>
|
||||
- Sign and magnitude<br/>
|
||||
|
||||
# TODO
|
||||
- Sign and magnitude<br/>
|
||||
- Complex binary* <br/>
|
||||
|
||||
# Why the fuck is this a thing?
|
||||
|
@ -17,46 +17,10 @@ while True:
|
||||
|
||||
Binary Addition
|
||||
Floating point binary
|
||||
Twos compliment,
|
||||
Sign & Magnitude,
|
||||
Twos compliment, Sign & Magnitude, Complex binary
|
||||
'''
|
||||
type_int = random.randint(0,4)
|
||||
type_int = random.randint(0,3)
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user