implmented a decode to all standard bases flag

This commit is contained in:
ika4422 2026-04-13 11:34:55 +01:00
parent b68815c29c
commit ca1e27a84e
No known key found for this signature in database
GPG key ID: F7FBF981D2A33785
3 changed files with 16 additions and 3 deletions

View file

@ -69,7 +69,7 @@ pub fn run_encode(input: &str, base: u32, text: bool) {
}
}
pub fn run_decode(input: &str, base: u32, text: bool) {
pub fn run_decode(input: &str, base: u32, text: bool, all_bases: bool) {
let decode_as_text = text || input.split_whitespace().count() > 1;
if decode_as_text {
@ -93,7 +93,16 @@ pub fn run_decode(input: &str, base: u32, text: bool) {
println!("{}", decoded_chars);
} else {
match from_dollcode(input) {
Ok(val) => println!("{}", val.to_str_radix(base)),
Ok(val) => {
if all_bases {
println!("bin :: {}", val.to_str_radix(2));
println!("oct :: {}", val.to_str_radix(8));
println!("dec :: {}", val.to_str_radix(10));
println!("hex :: {}", val.to_str_radix(16));
} else {
println!("{}", val.to_str_radix(base));
}
}
Err(e) => {
eprintln!("Error: {}", e);
process::exit(1);

View file

@ -50,6 +50,6 @@ fn main() {
} else if let Some(input) = args.encode {
commands::run_encode(&input, args.base.radix(), args.text);
} else if let Some(input) = args.decode {
commands::run_decode(&input, args.base.radix(), args.text);
commands::run_decode(&input, args.base.radix(), args.text, args.all_bases);
}
}

View file

@ -23,6 +23,10 @@ pub struct Args {
/// Input/output base for integers (2-36, or bin/oct/dec/hex/..)
pub base: Base,
#[arg(long, default_value_t = false)]
/// Output result in binary, octal, decimal and hex
pub all_bases: bool,
#[arg(long, default_value_t = false)]
/// Will generate codes without encoding it into dollcode
pub no_doll: bool,