How do I do unsigned comparsion between two vectors having 1s and 0s?
조회 수: 2 (최근 30일)
이전 댓글 표시
x = '10000001000000000000000000000000'
y = '00000000000001010110001111000000'
Let's say x is the binary representation of a 32-bit unsigned number. y is also same.
I want to have unsigned comparison between both of them. That means x(1) and y(1) are the MSB and the comparsion should start from there till we reach LSB.
Thanks.
댓글 수: 0
채택된 답변
Chunru
2022년 3월 29일
x = '10000001000000000000000000000000'
y = '00000000000001010110001111000000'
% Convert the binary to decimal
xd = bin2dec(x)
yd = bin2dec(y)
% compare the decimal number
xd > yd
댓글 수: 2
Chunru
2022년 3월 29일
It works forup to 53 binary bits (?).
If you have more bits to compare, you can use symbolic computation:
x = '0b100000010000000000000000000000001000000000000000000000000011';
y = '0b000000000000010101100011110000001000000000000000000000000011';
xs = sym(x)
ys = sym(y)
isAlways(xs > ys)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!