Contest Python: ACSL › Unit 1 — Computer Number Systems

Exercises: Unit 1 — Computer Number Systems

There are two kinds of exercises here, just as on an ACSL contest.

  • Short-answer: work it out with pencil and paper and write one exact answer. Write a number in a base without the small base subscript: if the question asks for base 8, the answer to "45 in base 8" is 55. Write hex digits as capital letters (2D, not 2d), leave out leading zeros, and write fractions in lowest terms, such as 5/8.
  • Programming: write a complete program that reads the input with input() and prints exactly the output described. Save it as a .py file and run it from a terminal, typing the sample input or feeding it a file.

Each exercise is marked with the lowest ACSL division it belongs to. Do every exercise at or below your division. Exercises 1 to 9 are an Elementary practice test: no programming, only what Lesson 1 teaches. Exercises marked Challenge are extra practice for when you want more.

Exercise 1: Binary to Decimal

  • Division: Elementary

What is 10110₂ in base 10?

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 2: Octal to Decimal

  • Division: Elementary

What is 237₈ in base 10?

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 3: Binary to Octal

  • Division: Elementary

Write 110101101₂ in base 8.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 4: Binary to Hex

  • Division: Elementary

Write 1011110₂ in base 16.

How this is checked: Checked by comparing your answer with the expected answer, ignoring capital letters.

Answer format: A hexadecimal number: base-16 digits only, with capital letters A–F for the digits after 9 (as in `2D`), no base subscript and no leading zeros. Small letters are accepted too.

For parents and teachers: report a problem

Exercise 5: Binary Addition

  • Division: Elementary

Find 1011₂ + 111₂. Write the answer in base 2.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 6: Octal Subtraction

  • Division: Elementary

Find 75₈ − 26₈. Write the answer in base 8.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 7: Which Is Largest?

  • Division: Elementary

Here are three numbers:

  • 1111000₂
  • 171₈
  • 77₁₆

Which one is the largest? Write its value in base 10.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 8: How Much Green?

  • Division: Elementary

The colour #1E90FF is a bright sky blue. How much green is in it? Write the amount in base 10.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 9: Count the Ones

  • Division: Elementary

How many 1s are in the binary form of 173₁₀?

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 10: Octal to Hex

  • Division: Junior

Write 5273₈ in base 16.

How this is checked: Checked by comparing your answer with the expected answer, ignoring capital letters.

Answer format: A hexadecimal number: base-16 digits only, with capital letters A–F for the digits after 9 (as in `2D`), no base subscript and no leading zeros. Small letters are accepted too.

For parents and teachers: report a problem

Exercise 11: Into Base 7

  • Division: Junior

Write 500₁₀ in base 7.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 12: Hex Subtraction

  • Division: Junior

Find C04A₁₆ − 3B7F₁₆. Write the answer in base 16.

How this is checked: Checked by comparing your answer with the expected answer, ignoring capital letters.

Answer format: A hexadecimal number: base-16 digits only, with capital letters A–F for the digits after 9 (as in `2D`), no base subscript and no leading zeros. Small letters are accepted too.

For parents and teachers: report a problem

Exercise 13: Times a Digit

  • Division: Junior

Find 3547₈ × 6₈. Write the answer in base 8.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Exercise 14: The Inverse Colour

  • Division: Junior

The inverse of a colour replaces each of its red, green and blue amounts by 255 minus that amount. What is the inverse of #3C8FD2? Write the answer as its six hex digits, without the #.

How this is checked: Checked by comparing your answer with the expected answer, ignoring capital letters.

Answer format: Six hex digits without the `#`, with capital letters A–F for the digits after 9 (as in `2D`). Small letters are accepted too.

For parents and teachers: report a problem

Exercise 15: Digits in Another Base

  • Division: Junior

The input is one line holding two integers, N and B. Print N written in base B, then one space, then the sum of its digits as a base-10 number. Digits above 9 are the letters A to F, and the letter's value (A = 10, …, F = 15) counts in the sum.

Constraints

  • 0 <= N <= 1000000
  • 2 <= B <= 16

Sample Input

500 7

Sample Output

1313 8

500 is 1313₇, and 1 + 3 + 1 + 3 = 8.

How this is checked: Checked by running your program on 5 test inputs (1 sample, 4 hidden) and comparing its output line by line.

For parents and teachers: report a problem

Exercise 16: The Biggest Card

  • Division: Junior

Each card holds a number and the base it is written in. Find the card with the largest value.

The first line holds N, the number of cards. Each of the next N lines holds one card: the digits of the number (hex digits as capital letters), a space, and its base B. Print the largest value, in base 10.

Constraints

  • 1 <= N <= 50
  • 2 <= B <= 16, and every digit on a card is a digit of that card's base.
  • Every value is between 0 and 1000000 in base 10.

Sample Input

3
101101 2
55 8
2F 16

Sample Output

47

The cards are worth 45, 45 and 47.

How this is checked: Checked by running your program on 4 test inputs (1 sample, 3 hidden) and comparing its output line by line.

For parents and teachers: report a problem

Exercise 17: Double Palindromes

  • Division: Intermediate

A palindrome reads the same forwards and backwards, such as 121 or 1001. Some numbers are palindromes both in base 10 and in base 2: 9 is 9 in base 10 and 1001 in base 2.

The input is one line holding two integers, A and B. Print how many whole numbers from A to B (including both) are palindromes in base 10 and in base 2.

Constraints

  • 1 <= A <= B <= 100000

Sample Input

1 10

Sample Output

5

They are 1, 3, 5, 7 and 9 (in base 2: 1, 11, 101, 111 and 1001).

How this is checked: Checked by running your program on 5 test inputs (1 sample, 4 hidden) and comparing its output line by line.

For parents and teachers: report a problem

Exercise 18: Octal Fraction

  • Division: Intermediate

Write 0.34₈ as a base-10 fraction in lowest terms.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: A base-10 fraction in lowest terms, written with `/`, such as `5/8`.

For parents and teachers: report a problem

Exercise 19: Hex Fraction

  • Division: Intermediate

Write 0.A8₁₆ as a base-10 fraction in lowest terms.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: A base-10 fraction in lowest terms, written with `/`, such as `5/8`.

For parents and teachers: report a problem

Exercise 20: A Fraction in Binary

  • Challenge
  • Division: Intermediate

Write 11/16 in base 2.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: A base-2 number with a point, such as `0.011`, written without the small base subscript.

For parents and teachers: report a problem

Exercise 21: The Mystery Base

  • Challenge
  • Division: Senior

In some base b, the number 132, written in base b, is equal to 56₁₀. What is b? Write it in base 10.

How this is checked: Checked by comparing your answer with the expected answer.

Answer format: a number

For parents and teachers: report a problem

Back to Unit 1 — Computer Number Systems