dec_to_bin: Convert decimal number to its binary representation

View source: R/operations.R

dec_to_binR Documentation

Convert decimal number to its binary representation

Description

Get the binary representation of any decimal number from 0 to (2^31) - 1. Doesn't work for larger numbers.

Usage

dec_to_bin(decimal_num, bits = 32)

Arguments

decimal_num

decimal number between 0 and (2^31) - 1

bits

number of bits to keep in the result counting from the right. Default value is 32.

Value

a binary string representation of the given decimal number.

Examples


# representing 0
dec_to_bin(0,1)
dec_to_bin(0,10)
dec_to_bin(0,32)
dec_to_bin(0)

# representing 24
dec_to_bin(24,6)
dec_to_bin(24,21)
dec_to_bin(24)
dec_to_bin(24,3) # note that this will cut the returned result so be careful!


usefun documentation built on Sept. 15, 2024, 1:06 a.m.