Skip to content

dejanfajfar/uberbyte.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

 █████  █████ █████                        ███████████              █████            
░░███  ░░███ ░░███                        ░░███░░░░░███            ░░███             
 ░███   ░███  ░███████   ██████  ████████  ░███    ░███ █████ ████ ███████    ██████ 
 ░███   ░███  ░███░░███ ███░░███░░███░░███ ░██████████ ░░███ ░███ ░░░███░    ███░░███
 ░███   ░███  ░███ ░███░███████  ░███ ░░░  ░███░░░░░███ ░███ ░███   ░███    ░███████ 
 ░███   ░███  ░███ ░███░███░░░   ░███      ░███    ░███ ░███ ░███   ░███ ███░███░░░  
 ░░████████   ████████ ░░██████  █████     ███████████  ░░███████   ░░█████ ░░██████ 
  ░░░░░░░░   ░░░░░░░░   ░░░░░░  ░░░░░     ░░░░░░░░░░░    ░░░░░███    ░░░░░   ░░░░░░  
                                                         ███ ░███                    
                                                        ░░██████                     
                                                         ░░░░░░                      

Bit manipulation for dummies

Rust Crates.io docs.rs

use uberbyte::UberByte;

fn main() {
    let my_byte: UberByte = UberByte::from(42);

    println!("{:b}", my_byte);
    for index in 0..7 {
        if my_byte.is_bit_set(index) {
            println!("Bit on position {} is set", index);
        } else {
            println!("Bit on position {} is not set", index);
        }
    }
}

📖 Backstory

When working with a hardware interface I found it always tedious to work with individual bits. Checking if one or the other is set and setting them in return to communicate with the hardware.

So to make my life easier and add some convenience to the whole matter I made this.

🚀 Getting started

Add UberByte to your project with:

cargo add uberbyte 

🎨 Features

  • Easily determine the state of each bit in the byte
  • Easily change the sate of each bit in the byte
  • Flip all bits in the byte
  • Provide constant bit masks for each bit
  • Provide OR, XOR, AND operations
  • A developer friendly implementation of a byte array

Usage

Check out the Examples for some basic usage scenarios.

💗 Contributing

If you want to contribute you can do this in many ways

Fork the repository

If you would like to introduce some changes to the project feel free to fork the project and do your changes.

It would then be nice if you create a pull request to reintegrate the changes you made.

Create a ticket

Found a bug? Missing a feature?

Create a ticket at our (github issues)[https://github.com/dejanfajfar/uberbyte.rs/issues].

Start a discussion

Any feedback that you do not want to put into the above form can just be dumped int our (github discussion page)[https://github.com/dejanfajfar/uberbyte.rs/discussions]

🪪 License

MIT

A great overview of the license is given at (tldrlegal.com)[https://www.tldrlegal.com/license/mit-license]

The license text can be found at (LICENSE)[https://github.com/dejanfajfar/uberbyte.rs/blob/main/LICENSE]