-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbit_tools.cpp
More file actions
47 lines (35 loc) · 1.03 KB
/
Copy pathbit_tools.cpp
File metadata and controls
47 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "bit_tools.h"
#ifndef bit_tools_use_macro
u32 rotr(const u32 word, const u8 amount){
return word >> amount | word << (32 - amount);
/* same as rotl
const u8 bit_count = 32; //countBits(word);
if(amount & (bit_count-1)) // mask only allow values up to 31
{
return word >> amount | word << (bit_count - amount);
}
return word;
*/
}
u32 rotl(const u32 word, const u8 amount) {
return word << amount | word >> (32 - amount);
/* slower but better handling for amount
const u16 bit_count = countBits(word);
if(amount & (bit_count-1)){
return word << amount | word >> (bit_count - amount);
}
return word;
*/
}
#endif
void showBits(u64 bits){
const u16 bit_count = countBits(u64) - 1;
//std::cout << "byte count: " << bit_count << '\n';
std::cout << "bits:";
for(u16 i=0; i<=bit_count; i++){
if(!(i%4)) std::cout << ' ';
if(i==32) std::cout << "| ";
std::cout << (bits >> (bit_count - i) & 1 );
}
std::cout << '\n';
}