Untitled
unknown
plain_text
2 years ago
589 B
8
Indexable
#include <stdio.h>
#include <unistd.h>
void printBinary(unsigned char n) {
for (int i = 7; i >= 0; i--)
printf("%d", (n >> i) & 1);
printf("\n");
}
void snakeMovement() {
unsigned char snake = 0b00000111;
int direction = 1;
while (1) {
printBinary(snake);
if ((snake == 0b00000111 && direction == -1) || (snake == 0b11100000 && direction == 1))
direction *= -1;
snake = (direction == 1) ? (snake << 1) : (snake >> 1);
usleep(500000);
}
}
int main() {
snakeMovement();
return 0;Editor is loading...
Leave a Comment