Compare commits
No commits in common. "8db5c9c7d0fc0a7992b078c0f305dce16ce8a005" and "acff092e30f5c8537936a5dfb0954e557ae430c1" have entirely different histories.
8db5c9c7d0
...
acff092e30
@ -8,9 +8,9 @@ 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/>
|
||||
|
||||
# TODO
|
||||
- Two's complement<br/>
|
||||
- Sign and magnitude<br/>
|
||||
- Complex binary* <br/>
|
||||
|
||||
|
@ -19,35 +19,8 @@ while True:
|
||||
Floating point binary
|
||||
Twos compliment, Sign & Magnitude, Complex binary
|
||||
'''
|
||||
type_int = random.randint(0,3)
|
||||
type_int = random.randint(0,2)
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user