https://github.com/lumarans30/dec2bin-rust
Three simple algorithms in Rust that convert a number from decimal to binary.
https://github.com/lumarans30/dec2bin-rust
big-int conversion decimal-to-binary rust
Last synced: 9 months ago
JSON representation
Three simple algorithms in Rust that convert a number from decimal to binary.
- Host: GitHub
- URL: https://github.com/lumarans30/dec2bin-rust
- Owner: LuMarans30
- License: mit
- Created: 2024-07-16T22:24:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-22T14:32:38.000Z (over 1 year ago)
- Last Synced: 2024-08-23T11:29:32.533Z (over 1 year ago)
- Topics: big-int, conversion, decimal-to-binary, rust
- Language: Rust
- Homepage: https://lumarans30.github.io/dec2bin-rust
- Size: 83 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Decimal to Binary Converter in Rust




A simple Rust implementation of a decimal to binary converter, inspired by my previous [C version](https://github.com/LuMarans30/three-version-decimal-to-binary).
I'm using this project to learn Rust and explore its features.
## Overview
This project provides a basic CLI for converting decimal numbers to their binary representations.
## Usage
To use this tool, run it from the command line:
```bash
cargo run [optional_decimal_number]
```
Alternatively, [precompiled binaries for most platforms](https://github.com/LuMarans30/dec2bin-rust/releases/latest) are available.
## Conversion Methods
1. **Iterative**: Uses a loop to perform the conversion. It divides the decimal number by 2 iteratively and gets the remainder.
2. **Recursive**: Same algorithm as iterative method, but recursively.
3. **Lookup Table**: Uses a lookup table that contains all possible 4-bit binary strings for faster conversion (generally the fastest method).
## Features
- Supports conversion of large numbers using the `num_bigint` crate
- Measures and displays the mean time taken for N iterations for each conversion method.
If you provide a decimal number as an argument, the program will use that for conversions. Otherwise, it will prompt you to enter a number.
## Contributing
This project was created as a learning exercise. While it's primarily for personal use, suggestions and improvements are welcome. Feel free to open an issue or submit a pull request if you have ideas to enhance its functionality.
## License
This project is open-source and available under the [MIT License](LICENSE).