Files
Bubberstation/code/modules/wiremod/components/math/decimal_conversion.dm
SkyratBot c9b268a72a [MIRROR] Integrated the component printer into the integrated circuit UI. You can now link integrated circuits to component printers [MDB IGNORE] (#9107)
* Integrated the component printer into the integrated circuit UI. You can now link integrated circuits to component printers (#62287)

Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>

* Integrated the component printer into the integrated circuit UI. You can now link integrated circuits to component printers

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Watermelon914 <3052169-Watermelon914@ users.noreply.gitlab.com>
2021-10-28 15:49:34 -04:00

31 lines
1.1 KiB
Plaintext

/**
* # Decimal Conversion Component
*
* Return a number from an array of binary inputs.
*/
/obj/item/circuit_component/binary_decimal/decimal_conversion
display_name = "Decimal Conversion"
desc = "Merges an array of binary digits, or bits, represented as 1 or 0 and often used in boolean or binary operations, into a decimal number."
category = "Math"
/obj/item/circuit_component/binary_decimal/decimal_conversion/populate_ports()
. = ..()
number = add_output_port("Number", PORT_TYPE_NUMBER)
/obj/item/circuit_component/binary_decimal/decimal_conversion/add_bit_port(index)
return add_input_port("Bit [index]", PORT_TYPE_NUMBER)
/obj/item/circuit_component/binary_decimal/decimal_conversion/remove_bit_port(datum/port/to_remove)
return remove_input_port(to_remove)
/obj/item/circuit_component/binary_decimal/decimal_conversion/input_received(datum/port/input/port)
if(!array_size)
return
var/result = 0
for(var/iteration in 1 to array_size)
var/datum/port/input/bit = bit_array[iteration]
if(bit.value)
result += (2 ** (iteration-1))
number.set_output(result)