how to add two binary digits of 8bit size?

1 view (last 30 days)
Mohit  Nanduri
Mohit Nanduri on 29 Nov 2021
Commented: Rik on 30 Nov 2021
input1 : 8 bit binary digit
input2 : 8 bit binary digit
output : 8 bit binary digit and carry should be stored in another variable
  2 Comments
Rik
Rik on 29 Nov 2021
This homework question is poorly phrased. It is very difficult to do anything in Matlab without using builtin functions.

Sign in to comment.

Accepted Answer

Chunru
Chunru on 29 Nov 2021
Edited: Chunru on 29 Nov 2021
a = '01001011';
b = '00100011';
c = '00000000';
% Cosider a carry bit
carry = 0;
% loop through from last bit to first bit
% add the bit from a and b and the carray
% update the results for the current bit and the carry bit
  4 Comments
Rik
Rik on 30 Nov 2021
The answer Chunru gave used the plus operator if I recall correctly. That is a builtin function.
Also, if it isn't homework, why would you limit yourself? Is there some part of binary addition you don't understand and want to do by hand?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by