What are the advantages of using bitwise operations?

Technology CommunityCategory: Bit ManipulationWhat are the advantages of using bitwise operations?
VietMX Staff asked 3 years ago
  • Basically, you use them due to size and speed considerations. Bitwise operations are incredibly simple and thus usually faster than arithmetic operations.
  • Bitwise operations come into play a lot when you need to encode/decode data in a compact and fast way. For example, to save space you may store multiple variables in a single 8-bit int variable by using each bit to represent a boolean.
  • Bitwise operations are absolutely essential when programming hardware registers in embedded systems where memory or CPU power is restricted. If you’re programming a microcontroller in C with 2kb of memory, every single bit counts, so the ability to pack 8 bools into a single byte may be critical.