Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SET 223
- // Prototipação
- char *binbin(int a);
- // Mascaramento de Bits
- int main()
- {
- int a;
- int r;
- printf("\n Type a value from 0 to 255: ");
- scanf("%d", &a);
- // &: Operador BitWise
- 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);
- }
- char *binbin(int a)
- {
- int i;
- static char bin[9];
- 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