From 6745a4ce2f09a37d1ca867f7c8b619361b08cdb0 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Sun, 31 Oct 2021 18:24:04 -0500 Subject: [PATCH] Convert binary to decimal --- bin2dec/src/main.rs | 13 ++++++++----- bin2dec/style.css | 9 +++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bin2dec/src/main.rs b/bin2dec/src/main.rs index baabe8f..ce3cd8a 100644 --- a/bin2dec/src/main.rs +++ b/bin2dec/src/main.rs @@ -3,13 +3,13 @@ use sycamore::prelude::*; fn main() { let inp = Signal::new(String::new()); let err = Signal::new(false); - let double = create_memo(cloned!((inp, err) => move || { + let decimal = create_memo(cloned!((inp, err) => move || { if *inp.get() == "" { return 0; } - if let Ok(parsed) = (*inp.get()).parse::() { + if let Ok(parsed) = u128::from_str_radix(&*inp.get(), 2) { err.set(false); - return parsed * 2; + return parsed; } else { err.set(true); return 0; @@ -23,12 +23,15 @@ fn main() { input(placeholder="Binary", bind:value=inp, style="text-align: center") (if *err.get() { template! { - span(style="color: red") { "unable to convert" } + span(style="color: red") { "Unable to convert to decimal" } } } else { template! {} }) - div(class="card") { (double.get()) } + div(class="card") { (decimal.get()) } + } + div(class="footer") { + "Powered by Rust 1.56 and WASM" } } }) diff --git a/bin2dec/style.css b/bin2dec/style.css index a17a92e..7ced3d2 100644 --- a/bin2dec/style.css +++ b/bin2dec/style.css @@ -12,4 +12,13 @@ margin-bottom: 1.5rem; word-wrap: break-word; white-space: pre-wrap; +} + +.footer { + position: fixed; + left: 0; + bottom: 0; + width: 100%; + text-align: center; + margin-bottom: 10px; } \ No newline at end of file