Skip to content

Instantly share code, notes, and snippets.

@edzillion
edzillion / toBinary-snip.lua
Last active November 19, 2023 16:47
Lua script to convert numbers from base 10 to base 2
-- By xDeltaXen from https://devforum.roblox.com/t/binary-conversion-in-lua/1718171
-- This function takes in a number and returns its binary form as a string
function toBinary(num)
local bin = "" -- Create an empty string to store the binary form
local rem -- Declare a variable to store the remainder
-- This loop iterates over the number, dividing it by 2 and storing the remainder each time
-- It stops when the number has been divided down to 0
while num > 0 do