Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void printBits(unsigned x) {
- for (int i = sizeof(x) * 8 - 1; i >= 0; i--) {
- printf("%d", 1 & (x >> i));
- if (i % 4 == 0) {
- putchar(' ');
- }
- }
- puts("");
- }
- int lsNib(unsigned a) {
- const unsigned mask = (1 << 4) - 1;
- const int nibNr = sizeof(a) * 2;
- int pos = nibNr;
- for (int i = 0; i < nibNr; i++) {
- if ((a >> (i * 4)) & mask) {
- pos = i;
- break;
- }
- }
- return pos;
- }
- int main(void) {
- unsigned a;
- scanf("%u", &a);
- printBits(a);
- printf("%d\n", lsNib(a));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement