kaushalmodi / baser

Emacs-Lisp Library for converting to and from Decimal, Hexadecimal and Binary numbers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Emacs-Lisp Library for converting to and from Decimal, Hexadecimal and Binary numbers

https://github.com/kaushalmodi/baser/actions/workflows/test.yml/badge.svg https://img.shields.io/badge/License-GPL%20v3-blue.svg

Installation

Clone this repo, have baser.el in the load-path and (require 'baser).

General Usage

Interactive

Functions called using M-x or key bindings.

With region selected

  1. Select a region in which you want to convert all the numbers.
  2. Run <conversion function> interactively.

Without region selected

  1. Run <conversion function> interactively.
  2. Type the number you want to convert.

Non-interactive

Call eval-expression (bound to M-: by default) and type the elisp expression of the conversion function.

Examples
(baser-dec-to-hex 100)       ;; => "00000064"
(baser-dec-to-hex "8'd55")   ;; => "37"
(baser-dec-to-hex "-8'd55")  ;; => "c9"

(baser-hex-to-dec "0x100")   ;; => 256
(baser-hex-to-dec "12'hfff") ;; => -1
(baser-hex-to-dec "16'hfff") ;; => 4095

(baser-hex-to-bin "0xabc")   ;; => "1010_1011_1100"

(baser-bin-to-hex "4'b1101") ;; => "d"

(baser-dec-to-bin "4'd3")    ;; => "0011"
(baser-dec-to-bin "-8'd3")   ;; => "1111_1101"

(baser-bin-to-dec "1111")    ;; => 15
(baser-bin-to-dec "4'b1111") ;; => -1
(baser-bin-to-dec "5'b1111") ;; => 15
    

Conversions

From BaseTo BaseFunction
10 (number or string)16 (string)baser-dec-to-hex
16 (string)10 (number)baser-hex-to-dec
16 (string)2 (string)baser-hex-to-bin
2 (string)16 (string)baser-bin-to-hex
10 (number or string)2 (string)baser-dec-to-bin
2 (string)10 (number)baser-bin-to-dec

Development

Running Tests

Run all tests

make test

Run tests matching a specific string

Run make test MATCH=<string>. For example, to run all tests where the name matches “hex-to-dec” completely or partially, run:

make test MATCH=hex-to-dec

About

Emacs-Lisp Library for converting to and from Decimal, Hexadecimal and Binary numbers

License:GNU General Public License v3.0


Languages

Language:Emacs Lisp 99.4%Language:Makefile 0.6%