Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- void printBin(uint64_t x) {
- for (int i = sizeof(x) * 8 - 1; i >= 0; i--) {
- printf("%d", (int)(1 & (x >> i)));
- }
- puts("");
- }
- int one(uint64_t x, int pos) {
- return 1 & (x >> pos);
- }
- int main(void) {
- uint64_t x;
- scanf("%lu", &x);
- printBin(x);
- int len = 0;
- for (int i = 0; i < sizeof(x) * 8; i++) {
- if (one(x, i)) {
- len++;
- } else {
- if (i && one(x, i - 1)) {
- printf("%d ", len);
- }
- len = 0;
- }
- }
- putchar('\n');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement