Skip to content

Terminal based bit manipulator in ncurses

License

GPL-3.0, GPL-3.0 licenses found

Licenses found

GPL-3.0
LICENSE
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

mellowcandle/bitwise

Repository files navigation

Bitwise

Terminal based bitwise calculator in curses

Build Statuscodecov Snap Status Coverity Scan Build Status

Bitwise is multi base interactive calculator supporting dynamic base convertion and bit manipulation. It's a handy tool for low level hackers, kernel developers and device drivers developers.

Some of the features include:

  • Interactive ncurses interface
  • Command line calculator supporting all bitwise operations.
  • Individual bit manipulator.
  • Bitwise operations such as NOT, OR, AND, XOR, and shifts.

Demo

Usage

bitwise can be used both Interactively and in command line mode.

Command line calculator mode

In command line mode, bitwise will calculate the given expression and will output the result in all bases including binary representation.

bitwise detects the base by the preface of the input (0x/0X for hexadecimal, leading 0 for octal, b for binary, and the rest is decimal).

Examples:

Simple base conversion

$ bitwise 0x12312311
Decimal: 305210129
Hexdecimal: 0x12312311
Octal: 02214221421
Size: 291.07MB
Binary:
0 0 0 1 0 0 1 0 | 0 0 1 1 0 0 0 1 | 0 0 1 0 0 0 1 1 | 0 0 0 1 0 0 0 1 
    31 - 24           23 - 16           15 -  8            7 -  0     

Calculator with predence

$ bitwise "0x30 * 0x20   30 / 2"
Decimal: 1551
Hexdecimal: 0x60F
Octal: 03017
Size: 1.51KB
Binary:
0 0 0 0 0 1 1 0 | 0 0 0 0 1 1 1 1 
    15 -  8            7 -  0 

Interactive mode

bitwise starts in interactive mode if no command line parameters are passed or if the -i | --interactive flag is passed. In this mode, you can input a number and manipulate it and see the other bases change dynamically. It also allows changing individual bits in the binary.

Navigation in interactive mode

To move around use the arrow keys, or use vi key bindings : h j k l . Leave the program by pressing q .

Binary specific movement

You can toggle a bit bit using the space key. You can jump a byte forward using w and backwards one byte using b .

Bitwise operation in interactive mode

Setting the bit width:

Reducing or extending the bit width interactively is also very easy, just use: ! for 8bit, @ for 16Bit, $ for 32Bit and * for 64Bit. When changing the bit width, the number is masked with the new width, so you might lost precision, use with care.

NOT:

Press ~ to perform the NOT operator.

Installation

Linux

Ubuntu

sudo add-apt-repository ppa:ramon-fried/bitwise
sudo apt-get update
sudo apt-get install bitwise

Snap

If your distribution supports Snap just type: sudo snap install bitwise

Arch

Your can use the AUR repository: https://aur.archlinux.org/packages/bitwise/

Windows

No, wait. really ???

Building from source

Make sure you have ncurses package installed

tar xfz RELEASE-FILE.TAR.GZ
cd RELEASE-DIR

./configure
make
sudo make install