-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<!-- Bug report: --> Binary to decimal not working as expected #366
Comments
So this is because most operations output a byte array, including From Binary so 111111111 becomes 0xFF,0x01 then To Decimal converts each to 255,1 This is as far as I've got to a fix using byte arrays. and it kind of works.. with binary as an input you need an additional Swap endianness operation to turn 111111111 into 0x01,0xFF then the below code works (otherwise 111111111 gets interpreted as 0xFF1 / 4081). src/core/operations/ToDecimal.mjs (full change here: OllieJC@5693d1e) run(input, args) {
const delim = Utils.charRep(args[0]);
if (args[1]) {
var res = "";
for (var i = 0; i < input.length; i++) {
res += input[i].toString(16);
}
return parseInt(res,16).toString();
} else {
return input.join(delim);
}
} edit: previous code did bit-shifting but that only works up to int32, above works int64 |
As @OllieGeek says, the 'From Binary' operation works on byte arrays, so the maximum binary value is 255. What you're looking for is 'From Base' which deals with numbers: https://gchq.github.io/CyberChef/#recipe=From_Base(2)&input=MTExMTExMTEx |
Ah nice @n1474335 - I didn't know From Base existed :) |
Closes gchq#366. This issue was caused by item IDs not being regenerated after the previous move, causing the second part of the move operation (delete previous) to fail. It was fixed by calling regenerate item IDs after item removal
Summary
If you try to convert more then 8 bits to decimal, it isn't working as expected.
For exemple :
Input : "111111111" (9 bits total)
Ouput : "255 1"
Expected output : "511"
What happend is that the first 8 bits were converted to 255 than the last one was converted to 1.
https://gchq.github.io/CyberChef/#recipe=From_Binary('Space')To_Decimal('Space')&input=MTExMTExMTEx
The text was updated successfully, but these errors were encountered: