https://github.com/multarix/baseconversions
Convert between Binary, Octal, Decimal, HEX
https://github.com/multarix/baseconversions
Last synced: 11 months ago
JSON representation
Convert between Binary, Octal, Decimal, HEX
- Host: GitHub
- URL: https://github.com/multarix/baseconversions
- Owner: Multarix
- License: mit
- Created: 2022-03-05T09:05:21.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-08T09:15:58.000Z (over 2 years ago)
- Last Synced: 2025-01-12T17:36:40.815Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 140 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BaseConversions
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
## Signed
A class that allows for the conversion between signed binary, octal, decimal, and hex numbers.
### Methods
#### .asDecimal( *bits* )
Converts the current value to a decimal number.
* bits - The number of bits to use for the conversion. Default is 8.
#### .asBinary( *bits* )
Converts the current value to a binary number.
* bits - The number of bits to use for the conversion. Default is 8.
#### .asOctal( *bits* )
Converts the current value to a octal number.
* bits - The number of bits to use for the conversion. Default is 8.
#### .asHex( *bits* )
Converts the current value to a hex number.
* bits - The number of bits to use for the conversion. Default is 8.
### Usage
```js
import { Signed } from 'base-conversions';
const base = 2;
const value = '10011001';
const signedNumber = new Signed(base, value);
console.log(signedNumber.asDecimal().newNumber) // -103
```
## Unsigned
A class that allows for the conversion between signed binary, octal, decimal, and hex numbers.
### Methods
#### .asDecimal()
Converts the current value to a decimal number.
#### .asBinary()
Converts the current value to a binary number.
#### .asOctal()
Converts the current value to a octal number.
#### .asHex()
Converts the current value to a hex number.
### Usage
```js
import { Unsigned } from 'base-conversions';
const base = 2;
const value = '10011001';
const unsignedNumber = new Unsigned(base, value);
console.log(unsignedNumber.asDecimal().newNumber) // 153
```
## BinaryEncodedDecimal
Two functions that allow for the conversion between binary and decimal for "floating point/ real" numbers
### toDecimal()
Converts the provided binary to a decimal number.
### toBinary()
Converts the provided decimal number to a floating point binary number.
# The purpose of this repo
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!