#how to convert u8 to array of bools?

26 messages · Page 1 of 1 (latest)

ashen umbra
#

// ___ 0 
//|_\_| 1 2A 3 dash 4
//|  \| 5 2B 6 
// ___ 7 
//                01234567

const _ONE :u8 =0b01001000;
const _TWO :u8 =0b10010101;```

trying to use these in a 7 segment display type project, and thought that carrying them around in a u8 might be fun. There appear to be ways to do this, but I didn't understand how to actually make any of them work.
#

Either that or just reading the bit directly

#

basically just want add a few characters to a string and then print whatever it is

print_8_segment(n);

desired output:
(four empty lines in terminal)

print_8_segment(n);```

desired output:


|__|
| |
___```

tulip pivot
#

you might want to look at this

ashen umbra
#

I read the docs, and still can't figure out how to perform the conversion

#

it seems to only be able to convert from bitmaps to u8s, I tried a few of its methods and didn't get anywhere

tulip pivot
#
pub fn from_value(data: <BitsImpl<SIZE> as Bits>::Store) -> Self

Construct a bitmap from a value of the same type as its backing store.
#

idk how to link functions in docs

ashen umbra
#

I couldn't get it to work, i did try that one

#

I can give you the error message

tulip pivot
#

sure, I can try

ashen umbra
#
const _TWO :u8 =0b10010101;

fn main(){
//cannot satisfy `BitsImpl<_>: Bits`
 let m = Bitmap::from_value(_TWO);

}```
#

i think it's designed to carry around a large number of bits in u8 containers so it's not sure what to do with a thing that already is a u8

tulip pivot
#
use bitmaps::Bitmap;
const _TWO: u8 = 0b10010101;

fn main() {
    let m = Bitmap::<8>::from_value(_TWO);
}
#

you have to specify the size

tulip pivot
#

The type used to store the bitmap will be the minimum unsigned integer type required to fit the number of bits, from u8 to u128. If the size is 1, bool is used. If the size exceeds 128, an array of u128 will be used, sized as appropriately.

ashen umbra
#

ah

#

ok i didn't know that was a thing rust could even do, neat

#

thank you!

tulip pivot
#

the implementation is a bit cursed

#

600 lines of macro invocations

ashen umbra
#

wild

tulip pivot