Math

题目列表

  • strobogrammatic number
  • count primes

Base conversion: decimal to/from binary

Decimal to binary

we get the result from right to left

  1. module to get the rightmost digit
  2. divide by 2 and go to 1

binary to decimal

we get the result from left to right

  1. result = result * 2 + cur_digit
  2. go to next digit