Skip to content

Commit

Permalink
chore: refactored code for brevity
Browse files Browse the repository at this point in the history
  • Loading branch information
Utilitycoder committed Sep 8, 2023
1 parent 52aeba5 commit c1d3862
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@ pub fn convert(
base_convert_from: &str,
) -> Result<(), std::num::ParseIntError> {
let convert_from = get_base_value(base_convert_from);

let convert_to = get_base_value(base_convert_to);

let number = Based::new(number_str, convert_from).to(convert_to).unwrap();

match base_convert_to {
"binary" => {
let number = Based::new(number_str, convert_from).to(convert_to).unwrap();
println!("Binary: {}", number.val);
}
"hex" => {
let number = Based::new(number_str, convert_from).to(convert_to).unwrap();
println!("Hexadecimal: 0x{}", number.val);
}
"octal" => {
let number = Based::new(number_str, convert_from).to(convert_to).unwrap();
println!("Octal: {}", number.val);
}
"decimal" => {
let number = Based::new(number_str, convert_from).to(convert_to).unwrap();
println!("Decimal: {}", number.val);
}
_ => {
Expand Down

0 comments on commit c1d3862

Please sign in to comment.