Convert between Binary, Octal, Decimal, HEX
All functions/ class methods return an object with the following properties:
- newNumber - The converted number
- conversion - The steps you would take to convert the number by hand
A class that allows for the conversion between signed binary, octal, decimal, and hex numbers.
Converts the current value to a decimal number.
- bits - The number of bits to use for the conversion. Default is 8.
Converts the current value to a binary number.
- bits - The number of bits to use for the conversion. Default is 8.
Converts the current value to a octal number.
- bits - The number of bits to use for the conversion. Default is 8.
Converts the current value to a hex number.
- bits - The number of bits to use for the conversion. Default is 8.
import { Signed } from 'base-conversions';
const base = 2;
const value = '10011001';
const signedNumber = new Signed(base, value);
console.log(signedNumber.asDecimal().newNumber) // -103
A class that allows for the conversion between signed binary, octal, decimal, and hex numbers.
Converts the current value to a decimal number.
Converts the current value to a binary number.
Converts the current value to a octal number.
Converts the current value to a hex number.
import { Unsigned } from 'base-conversions';
const base = 2;
const value = '10011001';
const unsignedNumber = new Unsigned(base, value);
console.log(unsignedNumber.asDecimal().newNumber) // 153
Two functions that allow for the conversion between binary and decimal for "floating point/ real" numbers
Converts the provided binary to a decimal number.
Converts the provided decimal number to a floating point binary number.
The purpose of this repo, is/was to annoy the hell out of an idiotic maths professor. The professor insisted on forcing students to convert 12bit or 8bit signed/ floating point numbers by hand. Obviously, such a task is tedious and arguably a complete waste of time, especially when the chances of you coming across binary that is of those lengths are marginal at best. Soooo... being the petty person I am, I wrote this to do it all for me.
Screw you professor! I hope your future students find this repo!