Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <Windows.h>
- typedef int bool;
- #define true 1
- #define false 0
- bool GetBit(unsigned char data, int bit){
- return (data >> bit) & 1 == 1;
- }
- //Binary right shift (rotate)
- char BRS(unsigned char data){
- return (data >> 1) | (data << (8 - 1));
- }
- //Binary left shift (rotate)
- char BLS(unsigned char data){
- return (data << 1) | (data >> (8 - 1));
- }
- void PrintByte(unsigned char data){
- int n;
- //left to right, least significant bit first, so this is reverse
- for (n = 7; n >= 0; n--){
- printf("%d", GetBit(data, n));
- }
- }
- void main(){
- int n;
- unsigned char test = 1;
- puts("BLS:");
- PrintByte(test);
- puts("\n-");
- for (n = 0; n < 8; n++){
- test = BLS(test);
- PrintByte(test);
- puts(" ");
- }
- puts("\nBRS:");
- test = 1;
- PrintByte(test);
- puts("\n-");
- for (n = 0; n < 8; n++){
- test = BRS(test);
- PrintByte(test);
- puts(" ");
- }
- unsigned long number = 0x5555555555555555;
- unsigned char * raw = &number;
- puts("\n-");
- //Read the long byte for byte backwards
- for (n = sizeof(number)-1; n >=0; n--){
- PrintByte(raw[n]);
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement