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 ビュー (過去 30 日間)
Hasin
Hasin 2024 年 1 月 26 日
回答済み: Udit06 2024 年 2 月 12 日
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 件のコメント
Stephen23
Stephen23 2024 年 1 月 26 日
編集済み: Stephen23 2024 年 1 月 26 日
"what will be the value of the multiplication of A and B in MATLAB?"
A = [1001]
A = 1001
B = [0101]
B = 101
A*B
ans = 101101
But I suspect that you actually meant A and B to be vectors... perhaps:
A = [1,0,0,1]
A = 1×4
1 0 0 1
B = [0,1,0,1]
B = 1×4
0 1 0 1
A.*B % element-wise array multiplication
ans = 1×4
0 0 0 1
A*B % matrix multiplication
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.
Rik
Rik 2024 年 1 月 26 日
Or perhaps a binary encoding was intended, in which case:
A=0b1001,B=0b0101
A = uint8 9
B = uint8 5
A*B
ans = uint8 45

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

回答 (1 件)

Udit06
Udit06 2024 年 2 月 12 日
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:
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.
You can refer to bin2dec and dec2bin functions for interconversion between the two number systems.
I hope it helps.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by