How do I do unsigned comparsion between two n-bit vectors having 1s and 0s?

1 回表示 (過去 30 日間)
Nadatimuj
Nadatimuj 2022 年 3 月 29 日
回答済み: Chunru 2022 年 3 月 29 日
x = '1000000100000000000000000000000000000000000001010110001111000000'
y = '0000000000000101011000111100000000000000000001010110001111000000'
Let's say x is the binary representation of a n-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. I think if I use bin2dec then there will be a flintmax issue for n>53.
Thanks.

採用された回答

Chunru
Chunru 2022 年 3 月 29 日
x = '1000000100000000000000000000000000000000000001010110001111000000'
x = '1000000100000000000000000000000000000000000001010110001111000000'
y = '0000000000000101011000111100000000000000000001010110001111000000'
y = '0000000000000101011000111100000000000000000001010110001111000000'
xs = sym(['0b' x])
xs = 
9295429630893056960
ys = sym(['0b' y])
ys = 
1517051168777152
isAlways( xs > ys )
ans = logical
1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by