Compare commits
2 Commits
acff092e30
...
8db5c9c7d0
Author | SHA1 | Date | |
---|---|---|---|
|
8db5c9c7d0 | ||
|
1f2ed35c44 |
@ -8,9 +8,9 @@ https://www.pgonline.co.uk/resources/computer-science/a-level-ocr/ocr-a-level-te
|
|||||||
- Conversions between bases (integers)<br/>
|
- Conversions between bases (integers)<br/>
|
||||||
- Binary addition<br/>
|
- Binary addition<br/>
|
||||||
- Floating point binary to denery conversion<br/>
|
- Floating point binary to denery conversion<br/>
|
||||||
|
- Two's complement<br/>
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
- Two's complement<br/>
|
|
||||||
- Sign and magnitude<br/>
|
- Sign and magnitude<br/>
|
||||||
- Complex binary* <br/>
|
- Complex binary* <br/>
|
||||||
|
|
||||||
|
@ -19,8 +19,35 @@ while True:
|
|||||||
Floating point binary
|
Floating point binary
|
||||||
Twos compliment, Sign & Magnitude, Complex binary
|
Twos compliment, Sign & Magnitude, Complex binary
|
||||||
'''
|
'''
|
||||||
type_int = random.randint(0,2)
|
type_int = random.randint(0,3)
|
||||||
|
|
||||||
|
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:
|
if type_int == 2:
|
||||||
print("What is this binary floating point number in denery?\n")
|
print("What is this binary floating point number in denery?\n")
|
||||||
int_length = random.randint(0,7)
|
int_length = random.randint(0,7)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user