How to convert logical vector to a number?
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tor Hammarbäck
el 4 de Abr. de 2022
Comentada: Bharath Venkataraman
el 5 de Abr. de 2022
Say I have a logical vector:
logicVector = logical([1 0 0 0 1 0 0 0]);
How do one convert it to a number?
From the code above the conversion would give 136 assuming it is unsigned and MSB first. Preferably the type would be fixed point. Best would be a function similar to matlabs 'fi'.
address = logicVec2fi(logicVector, false, true, 0); % logicVec2fi(input, signed, MSB, fraction length)
This will be used in simulink for a binary search where I get a boolean from each search-step which forms the index/address of a ram from the HDL Coder toolbox
0 comentarios
Respuesta aceptada
Más respuestas (1)
DGM
el 4 de Abr. de 2022
Well here's one way.
logicVector = logical([1 0 0 0 1 0 0 0]);
sum(2.^(numel(logicVector)-find(logicVector)))
I have no idea if that's the most appropriate for your application. I have no familiarity with using fi or Coder, so I'm just going to stop there.
Ver también
Categorías
Más información sobre HDL Coder en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!