Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- uint64_t replaceByte(uint64_t nr, uint8_t n, int p) {
- uint64_t shiftedN = n << (p * 8);
- uint64_t mask = 0xFF << (p * 8);
- return (~mask & nr) | shiftedN;
- }
- void showBits(uint64_t x) {
- for (int i = 63; i >= 0; i--) {
- printf("%llu", (x >> i) & 1);
- if (i % 4 == 0) {
- putchar(' ');
- }
- }
- puts("");
- }
- int main() {
- uint64_t nr;
- uint8_t n;
- int p;
- printf("nr="); scanf("%llu", &nr);
- printf("n="); scanf("%hhu", &n);
- printf("p="); scanf("%d", &p);
- showBits(nr);
- showBits(n << (p * 8ULL));
- showBits(replaceByte(nr, n, p));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement