- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitManipulation.java
More file actions
Latest commit
37 lines (25 loc) · 646 Bytes
/
Copy pathBitManipulation.java
File metadata and controls
37 lines (25 loc) · 646 Bytes
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
packagecracking.coding;
importjava.util.Hashtable;
publicclassBitManipulation {
publicstaticvoidmain(Stringargs[]){
System.out.println("differenc in bits are: "+bitDiff((byte)3,(byte)2));
Hashtablehash = newHashtable();
}
publicstaticintbitDiff(byteone, bytesecond){
intnumBits = 0;
intxored = (one ^ second);
for(inti = 0 ; i < 8 ; i++ ){
if((xored&1) >= 1)
numBits++;
xored>>=1;
}
returnnumBits;
}
publicintmergeInt(intn, intm, inti, intj){
intallones = ~0;
intleft = allones<<(j+1);
intright = (1<<i)-1;
intmask = left|right;
return ((n&mask)|(m<<i));
}
}