From 0192003b37b3796335d16ffc6f5c03652d71797b Mon Sep 17 00:00:00 2001 From: Joshua Kidder <49173900+Metekillot@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:59:23 -0400 Subject: [PATCH] Fixes binary conversion circuit component so that it does conversion into binary (#86528) ## About The Pull Request The binary conversion circuit component is totally busted at the moment, so I redid the logic and now it actually outputs a series of bits to represent whatever number you feed it. Additionally, it supports representing a negative number by setting the leftmost bit of your bit array to 1. ## Why It's Good For The Game Fixes a broken circuit component and makes it able to represent negative numbers ## Changelog :cl: Bisar fix: The binary conversion circuit component should work again. code: The component also now supports representing negative numbers. /:cl: --------- Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> --- .../wiremod/components/math/binary_conversion.dm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/code/modules/wiremod/components/math/binary_conversion.dm b/code/modules/wiremod/components/math/binary_conversion.dm index 8d90019b28c..8ef4067b955 100644 --- a/code/modules/wiremod/components/math/binary_conversion.dm +++ b/code/modules/wiremod/components/math/binary_conversion.dm @@ -37,6 +37,15 @@ if(!length(bit_array)) return - for(var/iteration in 1 to length(bit_array)) + var/to_convert = number.value + var/is_negative + if(number.value < 0) + is_negative = TRUE + to_convert = -to_convert + var/len = length(bit_array) + for(var/iteration in 1 to len) var/datum/port/output/bit = bit_array[iteration] - bit.set_output(number.value & (2 ** (iteration - 1))) + if(iteration == 1 && is_negative) + bit.set_output(1) + continue + bit.set_output(!!(to_convert & (1<< (len - iteration))))