필터 지우기
필터 지우기

Help on decimal to binary & decimal to hexadecimal

조회 수: 3 (최근 30일)
CK Yeap
CK Yeap 2018년 10월 17일
답변: Luna 2018년 10월 17일
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

답변 (2개)

Luna
Luna 2018년 10월 17일
편집: Luna 2018년 10월 17일
case '2' should be corrected with apostrophe

Luna
Luna 2018년 10월 17일
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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by