Sina Media Lab commited on
Commit
2f94536
·
1 Parent(s): 7172720
modules/number_system/twos_complement.py CHANGED
@@ -28,21 +28,21 @@ def generate_question():
28
 
29
  random.shuffle(options)
30
 
31
- question = f"What is the 2's complement of the binary number {number}?"
32
 
33
  num_expr = sp.sympify(f'0b{number}')
34
  ones_expr = sp.sympify(f'0b{ones_complement}')
35
  twos_expr = ones_expr + 1
36
 
37
  step_by_step_solution = [
38
- f"Step 1: Start with the original binary number: {number}",
39
  f"Step 2: Find the 1's complement by flipping all bits: {ones_complement}",
40
  f"Step 3: Add 1 to the 1's complement:",
41
  f" {ones_complement} + 1 = {bin(twos_expr)[2:].zfill(len(number))}",
42
  f"Step 4: The 2's complement of {number} is {correct_answer}."
43
  ]
44
 
45
- explanation = f"The 2's complement of {number} is {correct_answer}. It is calculated by inverting the bits and adding 1."
46
 
47
  return {
48
  "question": question,
 
28
 
29
  random.shuffle(options)
30
 
31
+ question = f"What is the 2's complement of the {bit_length}-bit binary number {number}?"
32
 
33
  num_expr = sp.sympify(f'0b{number}')
34
  ones_expr = sp.sympify(f'0b{ones_complement}')
35
  twos_expr = ones_expr + 1
36
 
37
  step_by_step_solution = [
38
+ f"Step 1: Start with the original {bit_length}-bit binary number: {number}",
39
  f"Step 2: Find the 1's complement by flipping all bits: {ones_complement}",
40
  f"Step 3: Add 1 to the 1's complement:",
41
  f" {ones_complement} + 1 = {bin(twos_expr)[2:].zfill(len(number))}",
42
  f"Step 4: The 2's complement of {number} is {correct_answer}."
43
  ]
44
 
45
+ explanation = f"The 2's complement of the {bit_length}-bit binary number {number} is {correct_answer}. It is calculated by inverting the bits and adding 1."
46
 
47
  return {
48
  "question": question,