Help on decimal to binary & decimal to hexadecimal

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

1 件のコメント

Jan
Jan 2018 年 10 月 17 日
What is your question?

サインインしてコメントする。

回答 (2 件)

Luna
Luna 2018 年 10 月 17 日
編集済み: Luna 2018 年 10 月 17 日

0 投票

case '2' should be corrected with apostrophe
Luna
Luna 2018 年 10 月 17 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2018 年 10 月 17 日

回答済み:

2018 年 10 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by