logo
Tags down

shadow

How can I convert binary bits into index in MATLAB


By : user2174577
Date : October 17 2020, 08:10 PM
To fix this issue Depending on the desired format of your input, you can use one of the 2 decimal to binary conversion function:
de2bi => return an array of 0 and 1, representing the binary number. dec2bin => return a string representation of the binary number.
code :
>> de2bi(3) % index antenna 1 and 2 (`3` decimal == `11` in binary):
ans =
     1     1
>> de2bi(10) % index antenna 2 and 4 (`10` decimal == `1010` in binary):
ans =
     0     1     0     1
>> Nt=7;
>> Ant_index = de2bi(10,Nt)
Ant_index =
     0     1     0     1     0     0     0
x_trans(Ant_index) = Symbole;
>> stringAntIndex = '1010'
stringAntIndex =
1010

decimalAntIndex = bin2dec(stringAntIndex)
decimalAntIndex =
    10

>> Ant_index = de2bi(decimalAntIndex,7)
Ant_index =
     0     1     0     1     0     0     0
>> stringAntIndex = '1010' ;
>> Ant_index = de2bi(bin2dec(stringAntIndex),Nt)
Ant_index =
     0     1     0     1     0     0     0
% Map the antenna to be active depending on decimal input
Antenna2Activate = {
    [1] ;   % antenna 1 active
    [2] ;   % antenna 2 active
    [3] ;   % ...
    [4] ;   % ...
    [1 2] ; % antenna 1 & 2 active
    [1 3] ; % antenna 1 & 3 active
    [1 4] ; % ...
    [2 3]   % antenna 2 & 3 active
    };

% Then to activate the proper antenna given a decimal input [decimalInput]:
Ant_index = Antenna2Activate{ decimalInput+1 } ;
x_trans(Ant_index) = Symbole;
decinput = 0:7 ;
for k=1:numel(Antenna2Activate)
    Ant_index = Antenna2Activate{ decinput(k)+1 } ;
    fprintf('Decimal input= %d \t Binary= %3s \t Ant_index: ',decinput(k),dec2bin(decinput(k),3))
    disp(Ant_index)
end
Decimal input= 0     Binary= 000     Ant_index:      1
Decimal input= 1     Binary= 001     Ant_index:      2
Decimal input= 2     Binary= 010     Ant_index:      3
Decimal input= 3     Binary= 011     Ant_index:      4
Decimal input= 4     Binary= 100     Ant_index:      1     2
Decimal input= 5     Binary= 101     Ant_index:      1     3
Decimal input= 6     Binary= 110     Ant_index:      1     4
Decimal input= 7     Binary= 111     Ant_index:      2     3


Share : facebook icon twitter icon

1x10^49 in decimal - how binary bits is that and how would you convert it to binary?


By : user1307073
Date : March 29 2020, 07:55 AM
hop of those help?
49 * log(10) / log(2) = 162.774477, so the binary representation would contain 163 bits.

Convert binary string greater than 52 bits to single in Matlab?


By : sTrAnGeRaKv
Date : March 29 2020, 07:55 AM
will be helpful for those in need dec2bin throws that error because a single is not capable of storing that much precision. Your very question asks an impossibility. You have two choices: store the value in something other than a floating point value, or throw away some precision before you convert.
Or describe more completely what you're trying to accomplish.
code :
str = char((rand(1, 100)>0.5) + '0');    % test data
data = uint8(bin2dec(reshape(str(1:end-mod(end,8)), [], 8)));

When making binary masks for working and isolating bits and bytes, what's the fastest way to convert from Binary to Hex?


By : Poojitha
Date : March 29 2020, 07:55 AM
like below fixes the issue Each set of four bits corresponds to one hex 'digit'. Learn those, then just start converting blocks of four from right to left. (If you're converting a bit string that's not a multiple of four bits, then just add zeros to the left end until it is for the last conversion.)
0000 : 0x0

Find location of a pattern of bits in a binary array in matlab


By : user3676589
Date : March 29 2020, 07:55 AM
wish of those help I have an array of binary data with long stretches of ones and zeros and I want to find the indices of when it changes. , Something like this should do the job:
code :
b = diff(a);                     % (assuming 'a' is a vector)
oneFromZero = find(b ==  1) + 1; % vector of indices of a '1' preceded by a '0'
zeroFromOne = find(b == -1) + 1; % vector of indices of a '0' preceded by a '1'

Matlab Binary Plot for Magnitude Representing the Whole 8 Bits


By : Scamper Stein
Date : March 29 2020, 07:55 AM
this one helps. Taking the idea from Cris Luengo into account, you'll get the following short script. I just wanted to add how to specifically set the xticklabel and yticklabel as you wanted it to have in your plot.
code :
% Binary values
bValues = { '00000000', 
            '00000001', 
            '00000010', 
            '00000011', 
            '00000100', 
            '00000101' };

% Double values
dValues = bin2dec(bValues);

% Output
figure(1);
stairs(dValues, dValues);
set(gca, 'xtick', dValues, 'xticklabel', dValues);
set(gca, 'ytick', dValues, 'yticklabel', bValues);
shadow
Privacy Policy - Terms - Contact Us © voile276.org