DEV Community

Zaw Htut Win
Zaw Htut Win

Posted on

highestOneBit ဆိုတာဘာလဲ

x (decimal) x (binary) highestOneBit(x)
1 0001 1
5 0101 4
10 1010 8
15 1111 8

ဒီနေရာမှာ Highest one bit ဆိုတာ decimal 15 က binary မှာ 1111.

1 ရဲ့ ဘယ်ဘက်ဆုံးမှာ ရှိနေတဲ့ 1 က index 0 မှာ ရှိတယ်။ ဒါကြောင့် 2^0 ဆိုတော့ highest one bit က 2

5 ရဲ့ ဘယ်ဘက်ဆုံးမှာ ရှိနေတဲ့ 1 က index 2 မှာ ရှိတယ်။ ဒါကြောင့် 2^2 ဆိုတော့ highest one bit က 4

10 ရဲ့ ဘယ်ဘက်ဆုံးမှာ ရှိနေတဲ့ 1 က index 3 မှာ ရှိတယ်။ ဒါကြောင့် 2^3 ဆိုတော့ highest one bit က 8

15 ရဲ့ ဘယ်ဘက်ဆုံးမှာ ရှိနေတဲ့ 1 က index 3 မှာပဲ ရှိသေးတယ်။ ဒါကြောင့် 2^3 ဆိုတော့ highest one bit က 8

Java မှာ

Integer.highestOneBit(n);
Enter fullscreen mode Exit fullscreen mode

ဆိုတဲ့ build in function ပါပါတယ်။

CPU-level optimization

Memory layouts

Predictable-performance code

တွေရေးတဲ့နေရာမှာ အသုံးများပါတယ်။

Top comments (0)