Bitwise Operators

Helpful script writing tricks and HowTo's
User avatar
jNizM
Posts: 2317
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Bitwise Operators

28 Jan 2014, 08:31

Bitwise Operators

Code: [Select all] [Download] GeSHi © Codebox Plus

&    -  bitwise and
| - bitwise or
^ - bitwise xor
~ - bitwise not
<< - bitwise shift left
>> - bitwise shift right



Bitwise AND [BitAnd] &

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




Bitwise OR [BitOr] |

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




Bitwise EXCLUSIVE OR [BitXor] ^

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




Bitwise NOT [BitNot] ~

Code: [Select all] [Download] GeSHi © Codebox Plus

  HEX   | Bits
----------------------------
~ 0x99 | 1 0 0 1 1 0 0 1
= |
0x66 | 0 1 1 0 0 1 1 0
----------------------------

MsgBox, % ~ 0x99 ;output: 0x66 (102)



Bitwise SHIFT LEFT [BitShiftLeft] <<

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




Bitwise SHIFT RIGHT [BitShiftRight] >>

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus




Bitwise ROTATE LEFT

Code: [Select all] [Download] GeSHi © Codebox Plus

  HEX   | Bits
----------------------------
0x03 | 1 1 0 0 0 0 0 0
RoL | RoL
= 0x81 | 1 0 0 0 0 0 0 1
----------------------------



Bitwise ROTATE RIGHT

Code: [Select all] [Download] GeSHi © Codebox Plus

  HEX   | Bits
----------------------------
0xC0 | 0 0 0 0 0 0 1 1
RoR | RoR
= 0x81 | 1 0 0 0 0 0 0 1
----------------------------



Useful Links:
- AHK.help - Operators
- Wikipedia - Bitwise operation
- C++ Tutorial: Bitwise Operators
- Low Level Bit Hacks You Absolutely Must Know
- bithacks.h - bit hacks header file
- Understanding Bitwise Operators


Todo:
- more explanations
- more examples
- |= &= ^= >>= <<=
- ...

BitRotate
a << b | (a & 0xFFFFFFFF) >> (32-b)
Last edited by jNizM on 17 Mar 2014, 06:16, edited 11 times in total.
[AHK] 1.1.28.02 x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
nnnik
Posts: 2907
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Bitwise Operators

28 Jan 2014, 15:56

a^b=(a&b)^(a|b)
Recommends AHK Studio

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 2 guests