Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SET 32
- // Prototipaçăo
- char *binbin(int a);
- int main()
- {
- int a;
- int r;
- printf("\n Type a value from 0 to 255: ");
- scanf("%d", &a);
- /*
- - Analogia: Operador Bitwise(a | SET) ~ Operador Matemático (a + 32) = 97
- | = Ou:
- Exemplo: 65 -> 01000001
- 32 -> 00100000
- 97 -> 01100001
- */
- r = (a | SET);
- printf("\n -> %5s = %d \n", binbin(a), a);
- printf("\n -> %5s = %d \n", binbin(SET), SET);
- printf("\n -> %5s = %d \n", binbin(r), r);
- printf("\n -> %d + %d = %d \n", a, SET, a + SET);
- return(0);
- }
- // Apresentaçăo do formato binário
- char *binbin(int a)
- {
- int i;
- static char bin[8];
- for( i = 0; i < 8; i++ )
- {
- if( a & 0x80 )
- {
- bin[i] = '1';
- a <<= 1;
- }
- else
- {
- bin[i] = '0';
- a <<= 1;
- }
- }
- bin[i] = '\0';
- return(bin);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement