# binary vector to a signed int

4 vues (au cours des 30 derniers jours)
Robert Scott le 31 Juil 2021
Modifié(e) : DGM le 31 Juil 2021
so as i understand binary vectors are a semi new thing to matlab?
I need to convery a binary vector to a signed int
I used to do this using the base2dec function and type cast it as a singed int
However, that is no longer feasible with a binary vector that is formed from using the hextobinaryvector function
So my question is, how can you create a signed int from a binary vector like the one returned from hextobinaryvector?
Thanks
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

DGM le 31 Juil 2021
Modifié(e) : DGM le 31 Juil 2021
I don't have the toolbox needed for hextobinaryvector(), but I assume the binary vector is just that. Given this solution:
One can extend it to accept binary values expressed as logical vectors instead of character vectors simply:
d = logical([1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]);
typecast(uint16(bin2dec(sprintf('%d',d))),'int16')
ans = int16 -32768
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Logical dans Help Center et File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by