Skip to content

kecci/go-bitwise-operations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Bitwise Operations

Bitwise operations are operations that manipulate individual bits of binary data at a low-level, rather than operating on the entire data. These operations treat each bit of a binary number as a separate entity and perform logical or arithmetic operations on them.

These bitwise operators are commonly used in various applications such as manipulating flags, performing efficient bit-level calculations, encoding/decoding data, or optimizing memory usage. They provide fine-grained control over the individual bits of binary data.

Bitwise

A bit wise operator perform logical or arithmetic operations on them.

  • AND
  • OR
  • XOR
  • NOT

Bitshift

A bit shift operator is a low-level operator that works on the individual bits of an integer. It takes two operands. One is the integer whose bits we want to shift. The other represents the number of shifts. The result of a bit shift is a new integer. Bit-shift operators are easy to use and execute quickly on modern multicore CPU systems. We use them to reduce memory usage and speed up execution.

  • LeftShift
  • RightShift
  • LeftCircularShift
  • RightCircularShift

Run Example

Command: go run main.go

Output Sample:

Original number: 1
LeftShift number: 2147483648 (Shifts: 31)
RightShift number: 0 (Shifts: 31)
LeftCircularShift number: 10000000000000000000000000000001 (Shifts: 31 Bits: 31)
RightCircularShift number: 00000001 (Shifts: 31 Bits: 31)

Source

About

Bitwise and Bitshift operations using Golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages