Is there a way to convert binary with Don't care to corresponding decimal values in MATLAB?

7 ビュー (過去 30 日間)
Nadatimuj 2022 年 3 月 8 日
コメント済み: Stephen23 2022 年 3 月 8 日
Is there a way to express don't care binary in MATLAB and get the decimal value? For example, 011x can be either 6 or 7 since the LSB is a don't care.
An Example Application: Suppose, I have a truth table of 5 variables [ABCDE]. It has 2^5 = 32 states. Now, if I say that I only care about states [ABE] and the rest are don't cares. Then there will be 2^3= 8 states that I care. How do I group those 32 states into 8 states? If I had the don't care decimals I would be done.
3 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
Nadatimuj 2022 年 3 月 8 日
Thanks. I think you are asking this because approx. 2^N possiibilies will easily blow up. In my application, there can be as many as 250 binary digits. For the example application I have mentioned, I have just written a code:
states = cared_states(5, [1 2 5])
function [grouped_states] = cared_states(number_spins, cared_spin_index)
% Date: 3/8/2022
%% Example Usage: cared_states(5, [2 3])
% number_spins should be the entire spin-state size [care+ don't cares]
% cared_spin_index should be a vector containing indices of the spins whose states you care
% grouped states will have 2^cared_states rows where each row will group
% states from all possible 2^all_states considering don't cares as the same states
%%
x= de2bi(0:2^number_spins-1,'left-msb');
y = de2bi(0:2^length(cared_spin_index)-1,'left-msb');
grouped_states=zeros(length(y),length(x)/length(y));
for i = 1:length(y)
for k = 1:length(cared_spin_index)
x(:,cared_spin_index(k))=y(i,k);
end
grouped_states(i,:) = unique(bi2de(x,'left-msb'));
end
end
Stephen23 2022 年 3 月 8 日
"Is there a way to convert binary ... to corresponding decimal values in MATLAB?"
"...there can be as many as 250 binary digits"
There is no inbuilt numeric class that will be able to hold such an integer with its full precision.

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

回答 (1 件)

Jan 2022 年 3 月 8 日
You can ectract the wanted bits by bitget such that the ignored bits simply vanish.
1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Nadatimuj 2022 年 3 月 8 日
Thanks. I am not sure if I am getting it. bitget gives you the binary values, right? But my problem was opposite, given that a binary string is 1101xxxx, I need all possible 2^4 decimal values.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by