If A= [1001] and B=[0101], what will be the value of the multiplication of A and B in MATLAB? I am new here. So, having trouble understanding
8 views (last 30 days)
Show older comments
If A= [1001] and B=[0101], what will be the value of the multiplication of A and B in MATLAB? I am new here. So, having trouble understanding
2 Comments
Stephen23
on 26 Jan 2024
Edited: Stephen23
on 26 Jan 2024
"what will be the value of the multiplication of A and B in MATLAB?"
A = [1001]
B = [0101]
A*B
But I suspect that you actually meant A and B to be vectors... perhaps:
A = [1,0,0,1]
B = [0,1,0,1]
A.*B % element-wise array multiplication
A*B % matrix multiplication
Rik
on 26 Jan 2024
Or perhaps a binary encoding was intended, in which case:
A=0b1001,B=0b0101
A*B
Answers (1)
Udit06
on 12 Feb 2024
Hi Hasin,
The multiplication of two binary numbers A =
and B =
follows the shift and add method, similar to long multiplication of decimal numbers. Let's multiply them as you would on paper:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1614741/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1614746/image.png)
1 0 0 1 (A)
× 0 1 0 1 (B)
------------
1 0 0 1 (A * 1)
0 0 0 0 (A * 0, shifted one position to the left)
1 0 0 1 (A * 1, shifted two positions to the left)
+0 0 0 0 (A * 0, shifted three positions to the left)
------------
1 0 1 1 0 1 (Result)
------------
Hence, the resultant of multiplication of A and B comes out to be
which is equivant to 45 in decimal number system.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1614751/image.png)
You can refer to bin2dec and dec2bin functions for interconversion between the two number systems.
I hope it helps.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!