Discusiones sobre Productos NI

cancelar
Mostrando los resultados de 
Buscar en lugar de 
Quiere decir: 

Obtener cantidad de bits de un byte

¡Resuelto!
Ir a solución

Que tal comunidad,

 

Soy estudiante de Ingeniería y estoy comenzando en el tema de programación en LabVIEW. Pues no soy muy experto. Así que les pido de su colaboración con un problema.

 

Adjunto hay un programa que convierte un número decimal y lo representa en hexadecimal, octal y en binario.

 

Mi problema está en que necesito mostrar cuántos bits, de mi arreglo de 8 bits, son necesarios para representar el número a convertir. Me explico con un ejemplo:

-Si el número a convertir es 8, en binario sería 0000 1000. Entonces debo mostrar un texto que lea "Se necesitan 4 bits para reprentar el número".

 

Estoy usando la versión de LabVIEW 2013 en Windows 10.

Muy amablemente me despido de ustedes y esperando que me puedan ayudar. Se agradece toda ayuda.

Walter

Estudiante de Ingeniería Electrónica

0 kudos
Mensaje 1 de 5
3.478 Vistas

He aqui el programa guardado en la version 8.5

Mis disculpas

0 kudos
Mensaje 2 de 5
3.427 Vistas
Solución
Aceptado por el autor del tema wavmy

Buena noches. Suena a mí como usted necesita encontrar el número mínimo de dígitos binray necesarios para expresar un número entero. El español no es mi lengua materna y estoy usando google translate. Log2 (x) podría haberse perdido en la escuela, Logarithms confundir a muchas personas.Capture.PNG


"Should be" isn't "Is" -Jay
Mensaje 3 de 5
3.376 Vistas

I speak English too.

 

So what I really need is as you inquired, the number of digits used to represent a binary number.

I was indeed thinking about a while loop that would divide the decimal number by 2 until the module reaches 1. And then get the number of iterations and that would be the amount of digits required to represent that number.

 

OK I already tried the while loop, but I can't get it to do the looped division it continues to take the same dividend. I attached my advance.

 

Hoping for your feedback

Walter

0 kudos
Mensaje 4 de 5
3.374 Vistas

For the loop, you need to learn about shift registers to operate on the result of the previous division. Currently, you are just repeating the same calculation forever.

 

A division by two is just a bit shift, so don't use anything orange. You can do it all in blue.

 

 

Two other possibilities:

  1. Search your reversed Boolean array for TRUE using "search array" and you can derive the size from the position.
  2. Just format in binary without leading zeroes (picture below) and look at the string length (might need an exception for an input of zero).

Descargar todos
Mensaje 5 de 5
3.351 Vistas