Effacer les filtres
Effacer les filtres

Help on decimal to binary & decimal to hexadecimal

3 vues (au cours des 30 derniers jours)
CK Yeap
CK Yeap le 17 Oct 2018
Réponse apportée : Luna le 17 Oct 2018
function out = simpleConv(val)
disp('Please select your option:\t 1 = decimal to binary \t 2 = decimal to hexadecimal\n')
switch input('Please select your option:','s')
case '1'
out = dec2bin('val');
case 2
out = dec2hex('val');
end
end

Réponses (2)

Luna
Luna le 17 Oct 2018
Modifié(e) : Luna le 17 Oct 2018
case '2' should be corrected with apostrophe

Luna
Luna le 17 Oct 2018
Hi,
Use your val without apostrophe, and add apostrophe to case 2. Call your function as an example: simpleConv(5)
function out = simpleConv(val)
disp('Please select your option:\t 1 = decimal to binary \t 2 = decimal to hexadecimal\n')
switch input('Please select your option:','s')
case '1'
out = dec2bin(val);
case '2'
out = dec2hex(val);
end
end

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by