0

Would anyone know how to convert a binary number into a string that represents its digits ?

let  s: u32 = 0b00100000001011001100001101110001110000110010110011100000;

I need study different parts of this binary number by cuting it into pieces (ex first 5 digits, then digit 6 to 15, etc...).

In order to do so, I'm thinking using string slices but first I need to convert the binary number into a string ( "00100000010110011...").

Thank you !

Herohtar
  • 5,347
  • 4
  • 31
  • 41
Witaek
  • 33
  • 4

1 Answers1

2

Use binary format:

fn main() {
    let s: u64 = 0b00100000001011001100001101110001110000110010110011100000u64;
    let s_str: String = format!("{s:b}");
    println!("{s_str}");
}

Playground

Netwave
  • 40,134
  • 6
  • 50
  • 93