Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

decimal to binary

def dec2bin_recurs(n: int) -> int:
    assert n >= 0 and isinstance(n, int), "Input must be positive integer"
    if not n: return n
    return int(f'{dec2bin_recurs(n//2)}{n%2}')
Comment

Decimal to Binary

# Function to convert decimal number
# to binary using recursion
def DecimalToBinary(num):
     
    if num >= 1:
        DecimalToBinary(num // 2)
    print(num % 2, end = '')
 
# Driver Code
if __name__ == '__main__':
     
    # decimal value
    dec_val = 24
     
    # Calling function
    DecimalToBinary(dec_val)
Comment

Convert Number To Binary


function convertToBinary(x) {
    let bin = 0;
    let rem, i = 1;
    /*rem is the remaining Number, i is the current step total, bin is the binary answer*/
    while (x != 0) {
        rem = x % 2;
             x = parseInt(x / 2);
        bin = bin + rem * i;
        i = i * 10;
    }
return bin;
}

console.log(convertToBinary(4))
Comment

decimal to binary

#include <iostream>
#include <stdlib.h>

int main ()
{
    int i;
    char buffer [33];
    printf ("Enter a number: ");
    scanf ("%d",&i);
    itoa (i,buffer,10);
    printf ("decimal: %s
",buffer);
    itoa (i,buffer,16);
    printf ("hexadecimal: %s
",buffer);
    itoa (i,buffer,2);
    printf ("binary: %s
",buffer);
    return 0;
}
Comment

how to convert decimal to binary

def decimalToBinary(n):
    return bin(n).replace("0b", "")
   
# Driver code
if __name__ == '__main__':
    print(decimalToBinary(8))
    print(decimalToBinary(18))
    print(decimalToBinary(7))
Comment

decimal to binary

  std::string binary = std::bitset<8>(n).to_string();
Comment

decimal to binary

# Function to print binary number using recursion
def convertToBinary(n):
   if n > 1:
       convertToBinary(n//2)
   print(n % 2,end = '')

# decimal number
dec = 34

convertToBinary(dec)
print()
Comment

PREVIOUS NEXT
Code Example
Python :: print column name and index 
Python :: Show column names and indexes dataframe python 
Python :: get number of row dataframe pandas 
Python :: Heroku gunicorn flask login is not working properly 
Python :: how to make a modulo in python 
Python :: infinity range or infinity looping 
Python :: flask echo server 
Python :: python program to calculate factorial of a number. 
Python :: unzipping the value using zip() python 
Python :: Python String index() 
Python :: Python OrderedDict - LRU 
Python :: python str and repr 
Python :: TypeError: Object of type DictProxy is not JSON serializable 
Python :: python get num chars 
Python :: when to use python sets 
Python :: Forth step - Creating new app 
Python :: pyqt5 tab order 
Python :: Command "python setup.py egg_info" failed setuptools/ gunicorn 
Python :: python pytest use same tests for multiple modules 
Python :: merge python list items by index one after one 
Python :: python download from digital ocean spaces boto3 
Python :: calculate time between datetime pyspark 
Python :: What is shadows built in name? 
Python :: train object detection model 
Python :: intersect and count in sql 
Python :: Are angles of a parallelogram equal? 
Python :: find a string hackereank 
Python :: get queryset 
Python :: mudopy 
Python :: Percentage change between the current and the prior element. 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =