Soumyaable

Trial

while True:  
a=input('Enter positive integer= ')  
if a>'0':    
print('Valid')  
else:    
print('Invalid')
while (true) { let z = prompt(‘Type D for Decimal conversion,\nB for Binary conversion,\nO for Octal conversion,\nH for Hexadecimal conversion\n’).toUpperCase(); console.log(); function dash() { console.log(‘—————‘); } if (z === ‘D’) { let a = prompt(‘Enter Decimal value= ‘); if (!isNaN(a)) { a = parseInt(a); let b = a.toString(2); let c = a.toString(8); let d = a.toString(16).toUpperCase(); console.log(`Binary of ${a} is ${b}`); console.log(`Octal of ${a} is ${c}`); console.log(`Hexadecimal of ${a} is ${d}`); dash(); } else { console.log(‘Invalid input’); dash(); } } console.log(); if (z === ‘B’) { let a = prompt(‘Enter Binary value= ‘); let a1 = a; if (/^[01]+$/.test(a)) { let decimalValue = parseInt(a, 2); let c = decimalValue.toString(8); let d = decimalValue.toString(16).toUpperCase(); console.log(`Decimal of ${a1} is ${decimalValue}`); console.log(`Octal of ${a1} is ${c}`); console.log(`Hexadecimal of ${a1} is ${d}`); dash(); } else { console.log(‘Invalid input’); dash(); } } console.log(); if (z === ‘O’) { let a = prompt(‘Enter Octal value= ‘); let a1 = a; if (/^[0-7]+$/.test(a)) { let decimalValue = parseInt(a, 8); let b = decimalValue.toString(2); let d = decimalValue.toString(16).toUpperCase(); console.log(`Decimal of ${a1} is ${decimalValue}`); console.log(`Binary of ${a1} is ${b}`); console.log(`Hexadecimal of ${a1} is ${d}`); dash(); } else { console.log(‘Invalid input’); dash(); } } console.log(); if (z === ‘H’) { let a = prompt(‘Enter Hexadecimal value= ‘).toUpperCase(); let a1 = a; if (/^[0-9A-F]+$/.test(a)) { let decimalValue = parseInt(a, 16); let b = decimalValue.toString(2); let c = decimalValue.toString(8); let d = decimalValue.toString(16).toUpperCase(); console.log(`Decimal of ${a1} is ${decimalValue}`); console.log(`Binary of ${a1} is ${b}`); console.log(`Octal of ${a1} is ${c}`); dash(); } else { console.log(‘Invalid input’); dash(); } } console.log(); }

Leave a Reply

Scroll to Top