Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- const int len = 8;
- uint64_t concat(uint8_t n[]) {
- uint64_t r = 0;
- for (int i = 0; i < len; i++) {
- r |= 1ULL * n[i] << (8ULL * i);
- }
- return r;
- }
- void showBits(uint64_t x, int msb) {
- for (int i = msb; i >= 0; i--) {
- printf("%llu", (x >> i) & 1);
- if (i % 4 == 0) {
- putchar(' ');
- }
- }
- }
- int main() {
- uint8_t n[len];
- for (int i = 0; i < len; i++) {
- printf("n%d=", i); scanf("%hhd", &n[i]);
- }
- for (int i = len - 1; i >= 0; i--) {
- showBits(n[i], sizeof(n[i]) * 8 - 1);
- }
- puts("");
- uint64_t r = concat(n);
- showBits(r, sizeof(r) * 8 - 1);
- puts("");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement