Split a binary sequence into two parts one integer part and one decimal part

3 vues (au cours des 30 derniers jours)
Panagiota chita
Panagiota chita le 2 Fév 2022
Commenté : Panagiota chita le 2 Fév 2022
I want to split for instance this binary sequence: '100101' and I want the first 4 bits to represent my integer part while the rest 2 bits the decimal part ->1001.01
There is a way to "put" the dot (.) somewho in matlab so 100101 = 9.25
(I generated a population constisted of 100 chromosomes and each chromosome represents 4 variables. So i split the binary sequence into 4 parts (24/4) and now i want to correspond each value to my variable but I cannot split and convert my binary sequence in two parts)

Réponses (1)

Mathieu NOE
Mathieu NOE le 2 Fév 2022
hello
try this :
% solution
a = 100101;
decimal_position = 2;
b = num2str(a);
d = bin2dec(b)/2^decimal_position;

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by