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
🆑 Bisar
fix: The binary conversion circuit component should work again.
code: The component also now supports representing negative numbers.
/🆑

---------

Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
This commit is contained in:
Joshua Kidder
2024-09-10 16:59:23 -04:00
committed by GitHub
parent d810b5b7e9
commit 0192003b37
@@ -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))))