Bit manipülasyonlarını, bilgisayar aritmetiğinde elde ettiğiniz verinin bitleri üzerinde değişiklikler/kontroller yaparak, elde etmek istediğiniz sonuca genellikle daha hızlı bir şekilde erişmenizi sağlayacak işlemler bütünü olarak adlandırabiliriz.
1. Kısım: https://youtu.be/OgphAV9JIKc
► Bit manipulation: https://en.wikipedia.org/wiki/Bit_manipulation
Bit manipulation is the act of algorithmically manipulating bits or other pieces of data shorter than a word. Computer programming tasks that require bit manipulation include low-level device control, error detection and correction algorithms, data compression, encryption algorithms, and optimization. For most other tasks, modern programming languages allow the programmer to work directly with abstractions instead of bits that represent those abstractions. Source code that does bit manipulation makes use of the bitwise operations: AND, OR, XOR, NOT, and possibly other operations analogous to the boolean operators; there are also bit shifts and operations to count ones and zeros, find high and low one or zero, set, reset and test bits, extract and insert fields, mask and zero fields, gather and scatter bits to and from specified bit positions or fields. Integer arithmetic operators can also effect bit-operations in conjunction with the other operators.
Videoda olan metodların text hallerini şuradan alabilirsiniz: https://pastecode.io/s/jHQ2FokF1n
► Bir manipülasyonları nerelerde kullanılır?
Eğer “bit manipülasyonu”nun faydalarını elde edemeyeceğiniz bir proje ise, muhtemelen bunları kullanmamalısınız. Tıpki bir çok enterprise uygulama gibi. İyi tarafları hızlı olmaları, kötü(?) tarafları anlaşılabilirliğin düşük olması, kod okunabilirliğini azaltmaları ve maintain edilebilmelerinin zorluğu diyebilirim.
Bunun dışında, en küçük bir “performans” kaybı bile sizin için değerli ise, o zaman bunları kullanmayı düşünebilirsiniz. Örnek olarak, C ile driver geliştirirken, en derin seviyede bir matematiksel işlemler yapıyorsanız bunları kullanabilirsiniz. Genel olarak right shift ve left shift operatörleri, çarpma ve bölme işlemlerine göre genellikle hızlı çalışırlar. Tabi günümüz derleyicileri, bunları olabildiğince optimize ediyorlar hali hazırda.