Created
August 9, 2021 11:22
-
-
Save andrew-wilkes/f414a25e7c827ca1b04b7928596aba3c to your computer and use it in GitHub Desktop.
Count number of bits in a number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
""" | |
See: https://www.geeksforgeeks.org/count-total-bits-number/ | |
Given a positive number n, count total bit in it. | |
Input : 183 | |
Output : 8 | |
Input : 4096 | |
Output : 13 | |
""" | |
func _ready(): | |
var n = 4096 | |
var i = 1 | |
var num_bits = 0 | |
while i <= n: | |
i *= 2 | |
num_bits += 1 | |
print(num_bits) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment