.NET 6 Yenilikleri – IsPow2 ve RoundUpToPowerOf2

.NET 6 ile hayatımıza BitOperations sınıfı içerisinde 2 yeni metod girdi. BitOperations sınıfı genellikle bit manipülasyonları için kullanılan statik bir utility sınıfı.

Bu operasyonlar;

✔️IsPow2: Verilen bir int yada long değerinin 2’nin bir tam sayı kuvveti olup olmadığını döndürür.

Console.WriteLine(BitOperations.IsPow2(64)); /// true 

https://source.dot.net/#System.Private.CoreLib/BitOperations.cs,49

✔️RoundUpToPowerOf2: Verilen bir int ya da long değerinden büyük ya da eşit, en küçük 2’nin tam sayı kuvvetini döndürür.

Console.WriteLine(BitOperations.RoundUpToPowerOf2(100)); /// 128 

https://source.dot.net/#System.Private.CoreLib/BitOperations.cs,97

Videoda bahsettiğim, Leetcode içerisindeki Amazon mülakat sorusu Power of Two: https://youtu.be/wi5jAQozZQA

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.