Bitwise NOT operator in Golang Last Updated : 05 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Bitwise NOT operator in the programming world usually takes one number and returns the inverted bits of that number as shown below: Bitwise NOT of 1 = 0 Bitwise NOT of 0 = 1 Example: Input : X = 010101 Output : Bitwise NOT of X = 101010 But Golang doesn't have any specified unary Bitwise NOT(~) or you can say Bitwise Complement operator like other programming languages(C/C++, Java, Python, etc). Here, you have to use Bitwise XOR(^) operator as Bitwise NOT operator. But how? Let's understand how Bitwise XOR takes in any two equal length bit patterns and performs Exclusive OR operation on each pair of corresponding bits. 1 XOR 1 = 0 1 XOR 0 = 1 0 XOR 0 = 0 0 XOR 1 = 1 Here, you can see the result of XOR(M, N) = 1 only if M != N else it will be 0. So here, we will use the XOR operator as a unary operator to implement the one's complement to a number. In Golang, suppose you have a given bit M, so ^M = 1 ^ M which will be equal to one's complement or you can say the Bitwise NOT operator result. Example: Suppose you have the given bits as 010101. Input: 11111111 XOR 00001111 Output: 11110000 C package main import "fmt" func main() { // taking the number in the hexadecimal // form it is 15 i.e. 00001111 in 8-bit form var bitwisenot byte = 0x0F // printing the number in 8-Bit fmt.Printf("%08b\n", bitwisenot) // using the ^M = 1 ^ M fmt.Printf("%08b\n", ^bitwisenot) } Output: 00001111 11110000 Here, you can see, if we simply solve the Bitwise Not of 00001111 then it will be equal to 11110000. Comment More infoAdvertise with us Next Article How to trim a slice of bytes in Golang? N Nikitha Sri Follow Improve Article Tags : Go Language Go-Operators Similar Reads Bitwise Operators in C++ In C+, Bitwise Operators are the operators that are used to perform bit-level operations on the integers. While performing these operations, integers are considered as sequences of binary digits. These operators are useful for low-level programming, system programming, and optimizing performance.C++ 6 min read Bitwise Operators in LISP In this article, we will discuss the Bitwise operators in LISP. These operators are used to perform the manipulation of individual bits of a number. The truth table for bitwise AND, NAND, OR, XOR, NOR, & XNOR: aba and b a nand ba or b a xor b a nor b a xnor b00010011010111001110100110011100 Dif 4 min read bits Package in Golang Go language provides inbuilt support for bit counting and manipulation functions for the predeclared unsigned integer types with the help of the bits package. .bits-package-Golang-table { border-collapse: collapse; width: 100%; } .bits-package-Golang-table td { border: 1px solid #5fb962; text-align: 6 min read Bitwise OR Operator (|) in Programming In programming, Bitwise Operators play a crucial role in manipulating individual bits of data. One of the fundamental bitwise operators is the Bitwise OR operator (|). In this article, weâll discuss the Bitwise OR operator, its syntax, properties, applications, and optimization techniques, and concl 5 min read How to trim a slice of bytes in Golang? In Go language slice is more powerful, flexible, convenient than an array, and is a lightweight data structure. The slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. In the Go slice of bytes, you ar 3 min read not Operator in Python The not keyword in Python is a logical operator used to obtain the negation or opposite Boolean value of an operand. It is a unary operator, meaning it takes only one operand and returns its complementary Boolean value. For example, if False is given as an operand to not, it returns True and vice ve 3 min read Like