-
Lenguaje
C
-
Descripción
Convierte un número entero positivo, menor a 257 a sistema binario.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int bit_0, bit_1, bit_2, bit_3, bit_4;
int bit_5, bit_6, bit_7, numero;
printf ("Ingresa el valor de numero: ");
scanf ("%d", &numero);
(void) getchar ();
bit_0=(numero%256-numero%128)/128;
bit_1=(numero%128-numero%64)/62;
bit_2=(numero%64-numero%32)/32;
bit_3=(numero%32-numero%16)/16;
bit_4=(numero%16-numero%8)/8;
bit_5=(numero%8-numero%4)/4;
bit_6=(numero%4-numero%2)/2;
bit_7=numero%2;
printf ("Valor de bit 0: %d\n", bit_0);
printf ("Valor de bit 1: %d\n", bit_1);
printf ("Valor de bit 2: %d\n", bit_2);
printf ("Valor de bit 3: %d\n", bit_3);
printf ("Valor de bit 4: %d\n", bit_4);
printf ("Valor de bit 5: %d\n", bit_5);
printf ("Valor de bit 6: %d\n", bit_6);
printf ("Valor de bit 7: %d\n", bit_7);
putchar ('\n');
system ("pause");
return EXIT_SUCCESS;
}
#include <stdlib.h>
int main (void)
{
int bit_0, bit_1, bit_2, bit_3, bit_4;
int bit_5, bit_6, bit_7, numero;
printf ("Ingresa el valor de numero: ");
scanf ("%d", &numero);
(void) getchar ();
bit_0=(numero%256-numero%128)/128;
bit_1=(numero%128-numero%64)/62;
bit_2=(numero%64-numero%32)/32;
bit_3=(numero%32-numero%16)/16;
bit_4=(numero%16-numero%8)/8;
bit_5=(numero%8-numero%4)/4;
bit_6=(numero%4-numero%2)/2;
bit_7=numero%2;
printf ("Valor de bit 0: %d\n", bit_0);
printf ("Valor de bit 1: %d\n", bit_1);
printf ("Valor de bit 2: %d\n", bit_2);
printf ("Valor de bit 3: %d\n", bit_3);
printf ("Valor de bit 4: %d\n", bit_4);
printf ("Valor de bit 5: %d\n", bit_5);
printf ("Valor de bit 6: %d\n", bit_6);
printf ("Valor de bit 7: %d\n", bit_7);
putchar ('\n');
system ("pause");
return EXIT_SUCCESS;
}