UNPKG

@vsadx/true-binary

Version:
29 lines (20 loc) 949 B
# Export machine binary from `number` ```js import { Binary } from "@vsadx/true-binary" const some_num = 13 // `toString(2)` gives us the binary version of 13 some_num.toString(2) // this isn't how JavaScript sees numbers though, // it uses IEEE-754 floating point standard // give it a try! Binary.stringify(13) ``` You can learn a lot about why some mathmatical operations are fast but other, even similar ones, are slower. In some cases, using the IEEE 754 format directly increased operation speeds for game developers at one time. This raw binary format lets you make speed vs accuracy tradeoffs more explicitly. There are two methods so far; you can use `stringify` or `parse`. It is similar to the `JSON` object which also has those methods. In this case, there is no reviver parameter or much other configuration settings. #### `stringify(number: number, add_spaces: bool)` #### `parse(stringified_binary: string)`