add Int8 and int16

조회 수: 2 (최근 30일)
Aminata camara
Aminata camara 2021년 3월 18일
댓글: Aminata camara 2021년 3월 18일
how can I write a code for this:
By default, it is not possible to add an int8 value to an int16 value. Write a function that accepts an int8 argument and an int16 argument and adds them together, returning the resulting value as an int16 value.
what I started to write:
function out2=add_int(in1,in2)
%Write a function that accepts an int8 argument and an int16
%argument and adds them together, returning the resulting value as an int16 value.
out=int8(in1)+int16(in2);
out2=int16(out);

답변 (2개)

Stephen23
Stephen23 2021년 3월 18일
add_int(int8(127),int16(129))
ans = int16 256
function out = add_int(in1,in2)
out = int16(in1) + int16(in2);
end
  댓글 수: 3
Stephen23
Stephen23 2021년 3월 18일
...with a pretty good attempt.
Aminata camara
Aminata camara 2021년 3월 18일
Thank you so much for the response @Stephen Cobeldick. yeah it is a homework from my enginnering book on Matlab I try to do as many homework they provide on the book to get better practice. Thank you all for helping me.

댓글을 달려면 로그인하십시오.


Bjorn Gustavsson
Bjorn Gustavsson 2021년 3월 18일
Think about what input variables you have, what type they have and which one you need to cast to another data-type.

카테고리

Help CenterFile Exchange에서 Get Started with Control System Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by