Advertisement
imk0tter

NUMBER(S)_TO_NUMBER(S)

Jul 26th, 2024
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. def NUMBERS_TO_NUMBER(number, *numbers):
  2.     number += 1
  3.     for i in numbers:
  4.         number = (number * 2 - 1) * (2 ** i)
  5.     return number - 1
  6.  
  7. def NUMBER_TO_NUMBERS(number, count):
  8.     bits = []
  9.     for i in range(0, count):
  10.         number += 1
  11.         current_bit = 0
  12.  
  13.         #TODO: get current bit without iterating...
  14.         while (number / (2 ** current_bit)) % 2 == 0: current_bit += 1
  15.  
  16.         number = ((number / (2 ** current_bit) + 1) / 2) - 1
  17.         bits.insert(0, current_bit)
  18.  
  19.     return number, tuple(bits)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement