mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
'From Base' operation now supports numbers with fractional parts.
This commit is contained in:
parent
3788a9161a
commit
706423462d
2 changed files with 20 additions and 2 deletions
|
@ -46,7 +46,19 @@ const Base = {
|
|||
if (radix < 2 || radix > 36) {
|
||||
throw "Error: Radix argument must be between 2 and 36";
|
||||
}
|
||||
return parseInt(input.replace(/\s/g, ""), radix);
|
||||
|
||||
var number = input.replace(/\s/g, "").split("."),
|
||||
result = parseInt(number[0], radix) || 0;
|
||||
|
||||
if (number.length === 1) return result;
|
||||
|
||||
// Fractional part
|
||||
for (var i = 0; i < number[1].length; i++) {
|
||||
var digit = parseInt(number[1][i], radix);
|
||||
result += digit / Math.pow(radix, i+1);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue