Cómo convertir float number a Binario?
¿Puede alguien decirme cómo puedo convertir este número flotante: 12.25 a binario? Sé cómo convertir el "12", pero no el 0.25
Cualquier ayuda es muy apreciada. Gracias
33
Author: Abimaran Kugathasan, 2010-10-17
5 answers
Siga multiplicando el número después del decimal por 2 hasta que se convierta en 1.0:
0.25*2 = 0.50
0.50*2 = 1.00
Y el resultado está en orden inverso .01
22
Author: Abhi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-04 10:06:29
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-04 10:06:29
(d significa decimal, b significa binario)
- 12.25 d es tu flotador.
- Escribes 12d en binario y lo eliminas de tu float. Sólo el resto (.25d) se dejará.
- Escribes el punto.
- Mientras que el resto (0.25 d) no es cero (y / o desea más dígitos), multiplíquelo con 2 ( - > 0.50 d), elimine y escriba el dígito izquierdo del punto (0), y continúe con el nuevo resto (.50d).
13
Author: comonad,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-08 19:46:19
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-08 19:46:19
Considere el siguiente ejemplo
Convertir 2.625 a binario.
Consideraremos el entero y la parte fraccionaria por separado.
The integral part is easy, 2 = 10.
Para la parte fraccionaria:
0.625 × 2 = 1.25 1 Generate 1 and continue with the rest.
0.25 × 2 = 0.5 0 Generate 0 and continue.
0.5 × 2 = 1.0 1 Generate 1 and nothing remains.
Entonces 0.625 = 0.101, y 2.625 = 10.101.
Vea este enlace para más información.
13
Author: Govind Prabhu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-04 15:52:27
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-04 15:52:27
El valor flotante se almacena en el formato IEEE 754,por lo que no podemos convertir directamente como integer, char a binario. Pero podemos convertir flotador a binario a través de puntero.
main()
{
float a=7.5;
int i,*p; p=&a;
for (sizeof(int)*8-1;i>=0;i--)
printf("%d",(*p)>>i&1);
}
OUTPUT::0 10000001 11100000000000000000000---space for better clarification not included in part of the program.
3
Author: ilango victor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-11 18:04:32
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-11 18:04:32
x = float(raw_input("enter number between 0 and 1: "))
p = 0
while ((2**p)*x) %1 != 0:
p += 1
# print p
num = int (x * (2 ** p))
# print num
result = ''
if num == 0:
result = '0'
while num > 0:
result = str(num%2) + result
num = num / 2
for i in range (p - len(result)):
result = '0' + result
result = result[0:-p] + '.' + result[-p:]
print result #this will print result for the decimal portion
1
Author: iLabQC,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-17 16:50:09
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-17 16:50:09