20 lines
402 B
JavaScript
20 lines
402 B
JavaScript
|
function convertNumber(num) {
|
||
|
if (isNaN(num)) {
|
||
|
return "Please enter a valid number.";
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
binary: num.toString(2),
|
||
|
decimal: num.toString(10),
|
||
|
hexadecimal: num.toString(16).toUpperCase()
|
||
|
};
|
||
|
}
|
||
|
|
||
|
const number = 255;
|
||
|
console.log(convertNumber(number));
|
||
|
|
||
|
{
|
||
|
"binary"; "11111111",
|
||
|
"decimal"; "255",
|
||
|
"hexadecimal"; "FF"
|
||
|
}
|