├── README.md ├── binary.py ├── convert_d-b.py ├── decimal.cpp ├── decimaltobinary.py ├── dectobi.py ├── pyprogram.py ├── script.js └── script.py /README.md: -------------------------------------------------------------------------------- 1 | This Repo is for the Hacktoberfest Event 2021, to participate in this, all you have to do is make 4 PRs and you'll be qualified for the event. 2 | 3 | Steps for getting your PR merged: 4 | 5 | Fork this repo 6 | Add a script to convert decimal to binary using python 7 | Make pull request 8 | That's it!!! 9 | -------------------------------------------------------------------------------- /binary.py: -------------------------------------------------------------------------------- 1 | #Function to convert Decimal number 2 | # to Binary number 3 | def decimalToBinary(n): 4 | return bin(n).replace("0b","") 5 | # Driver code 6 | if __name__ == '__main__': 7 | print(decimalToBinary(8)) 8 | print(decimalToBinary(18)) 9 | print(decimalToBinary(7)) 10 | -------------------------------------------------------------------------------- /convert_d-b.py: -------------------------------------------------------------------------------- 1 | def decimalToBinary(num):if num > 1: 2 | decimalToBinary(num // 2) 3 | print(num % 2, end = '') 4 | number = int(input("Enter the decimal number: ")) 5 | 6 | #main() function 7 | decimalToBinary(number) 8 | -------------------------------------------------------------------------------- /decimal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int a[10], n, i; 6 | cout<<"Enter the number to convert: "; 7 | cin>>n; 8 | for(i=0; n>0; i++) 9 | { 10 | a[i]=n%2; 11 | n= n/2; 12 | } 13 | cout<<"Binary of the given number= "; 14 | for(i=i-1 ;i>=0 ;i--) 15 | { 16 | cout< 0): 9 | binary = ((temp%2)*(10**ctr)) + binary 10 | temp = int(temp/2) 11 | ctr += 1 12 | 13 | #output the result 14 | print("Binary of {x} is: {y}".format(x=decimal,y=binary)) 15 | -------------------------------------------------------------------------------- /dectobi.py: -------------------------------------------------------------------------------- 1 | # Function to print binary number using recursion 2 | def convertToBinary(n): 3 | if n > 1: 4 | convertToBinary(n//2) 5 | print(n % 2,end = '') 6 | 7 | # decimal number 8 | dec = 34 9 | 10 | convertToBinary(dec) 11 | print() 12 | -------------------------------------------------------------------------------- /pyprogram.py: -------------------------------------------------------------------------------- 1 | print("Enter the Decimal Number: ") 2 | dnum = int(input()) 3 | i = 0 4 | bnum = [] 5 | while dnum!=0: 6 | rem = dnum%2 7 | bnum.insert(i, rem) 8 | i = i+1 9 | dnum = int(dnum/2) 10 | 11 | i = i-1 12 | print("\nEquivalent Binary Value is:") 13 | while i>=0: 14 | print(end=str(bnum[i])) 15 | i = i-1 16 | print() 17 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | 31 | -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | # Function to convert decimal number 2 | # to binary using recursion 3 | def DecimalToBinary(num): 4 | 5 | if num >= 1: 6 | DecimalToBinary(num // 2) 7 | print(num % 2, end = '') 8 | 9 | # Driver Code 10 | if __name__ == '__main__': 11 | 12 | # decimal value 13 | dec_val = 24 14 | 15 | # Calling function 16 | DecimalToBinary(dec_val) 17 | --------------------------------------------------------------------------------