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 :: swap two lists without using third variable python 
Python :: default python packages 
Python :: name is not defined python 
Python :: how to run python code in python 
Python :: python import list from py file 
Python :: hmac sha256 python 
Python :: nrf24l01 arduino to raspberry pi struct 
Python :: how to compare list and int in python 
Python :: how to make code only go once python 
Python :: pca in python 
Python :: how to print random in python 
Python :: python isdigit 
Python :: python combine two columns into matrix 
Python :: convert method to str python 
Python :: python reverse dictionary 
Python :: for loop python 
Python :: how to close opened file in python 
Python :: dataframe select row by index value 
Python :: Python RegEx re.compile() 
Python :: pandas use dict to transform entries 
Python :: sum of even numbers 
Python :: format when turning float into string 
Python :: plt.hist bins 
Python :: how to become python developer 
Python :: NumPy invert Syntax 
Python :: what is serializer in django 
Python :: pandas save dataframe with list 
Python :: cross validation sklearn 
Python :: create dictionary without removing duplicates from dataframe 
Python :: WARNING: Ignoring invalid distribution c program files python39libsite-packages 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =