def decToBin(dec):
binary = "";
while(dec != 0):
binary = str(dec%2) + binary;
dec = int(dec/2);
return binary;
print(decToBin(int(input("ENTER DECIMAL"))));
1111011
def binToDec(bin):
dec = 0;
bin = str(bin);
for i in range(len(bin)):
dec += int(bin[i])*(2**(len(bin)-1-i));
return dec;
print(binToDec(1111));
15
def decToHex(dec):
hexadecimal = "";
while(dec != 0):
if(dec%16 <= 10):
hexadecimal= str(dec%16) + hexadecimal;
elif (dec%16 == 10):
hexadecimal= "A" + hexadecimal;
elif (dec%16 == 11):
hexadecimal= "B" + hexadecimal;
elif (dec%16 == 12):
hexadecimal= "C" + hexadecimal;
elif (dec%16 == 13):
hexadecimal= "D" + hexadecimal;
elif (dec%16 == 14):
hexadecimal= "E" + hexadecimal;
elif (dec%16 == 15):
hexadecimal= "F" + hexadecimal;
dec = int(dec/16);
return hexadecimal;
print(decToHex(1000));
3E8
def decToHex(decimal_number):
hexadecimal_number = ""
while decimal_number > 0:
remainder = decimal_number % 16
if remainder == 0:
hexadecimal_number = "0" + hexadecimal_number
elif remainder == 1:
hexadecimal_number = "1" + hexadecimal_number
elif remainder == 2:
hexadecimal_number = "2" + hexadecimal_number
elif remainder == 3:
hexadecimal_number = "3" + hexadecimal_number
elif remainder == 4:
hexadecimal_number = "4" + hexadecimal_number
elif remainder == 5:
hexadecimal_number = "5" + hexadecimal_number
elif remainder == 6:
hexadecimal_number = "6" + hexadecimal_number
elif remainder == 7:
hexadecimal_number = "7" + hexadecimal_number
elif remainder == 8:
hexadecimal_number = "8" + hexadecimal_number
elif remainder == 9:
hexadecimal_number = "9" + hexadecimal_number
elif remainder == 10:
hexadecimal_number = "A" + hexadecimal_number
elif remainder == 11:
hexadecimal_number = "B" + hexadecimal_number
elif remainder == 12:
hexadecimal_number = "C" + hexadecimal_number
elif remainder == 13:
hexadecimal_number = "D" + hexadecimal_number
elif remainder == 14:
hexadecimal_number = "E" + hexadecimal_number
elif remainder == 15:
hexadecimal_number = "F" + hexadecimal_number
decimal_number = decimal_number // 16
return hexadecimal_number
print(decToHex(100));
64
def decToHex(dec):
octal = "";
while(dec != 0):
octal= str(dec%8) + octal;
dec = int(dec/8);
return octal;
print(decToHex(1000));
1750
def octalToDec(octal):
dec = 0;
octal = str(octal);
for i in range(len(octal)):
dec += int(octal[i])*(8**(len(octal)-1-i));
return dec;
print(octalToDec(1111));
585