“Are you interested in learning more about the technical side of Factorio’s DLCs? Look no further! This guide will cover topics such as bit, byte, binary shift, and more. It’s important to note that this information was originally written in Ukrainian and has been translated using Deepl. So, if you spot any errors or have additional knowledge to share, please leave a comment. Get ready for a crash course on processor functioning, math, and even programming – all in the context of Factorio.”
Bit & byte
The game presents an example of one bit and it is a switch for electrical networks
Bytes are containers that store information from 1/0
8 bit = 1 byte
And to demonstrate the bit shift, I will use a 32-bit circuit
Below is a part of it, with white color indicating a byte and copper color indicating a bit
To confirm, here is the site[convertlive.com]
Binary and decimal numbers
To convert ordinary 13 to binary, use the division operation with the remainder
Thus, the binary representation of 13 is 1101
When converting a decimal number to binary, you use the method of division by 2. If the number is divisible by 2, you write 0 (there is no remainder), and if the number is not divisible by 2, you write 1 (because we get the remainder). This rule is applied at each step of dividing a decimal number by 2 until the result is 0. After that, the remainders are written in reverse order to get the binary representation of the number.
An example based on game logic
Next, we’ll use the online calculator, and this section is designed to help you understand the magic it creates
Most significant bit (MSB)
For a 4-bit 1010, the most significant bit will be 1010, and for an 8-bit 1011 1011, respectively 1011 1011
For example, if I take 1 and shift it by 31, we will get the maximum negative value for 32-bit programs –2147483648
In the photo, none of the indicators are on, because the value is negative
However, if there is a 30-bit offset, the value will be 1073741824
Example of the MSB on a calculator
32 bits
So, the representation of the maximum and minimum values for this bit depth is as follows
MIN -2 147 483 648 MAX 2 147 483 647
Feature:
If you add one to the maximum value, you get the minimum value
2 147 483 647
+1
-2 147 483 648
Similar to the minimum value
-2 147 483 648
-1
2 147 483 647
An overflow occurs when the result of an arithmetic operation goes beyond the possible range for a particular number format.
For example, in the binary representation of 32-bit numbers, if you add one to the maximum value, an overflow occurs, and the minimum value is obtained.
An example of overflow in life is the “tachometer”
When the maximum is reached, a new cycle begins
If you create a number of items close to the maximum value for 32 bits. The game may start to slow down and crash when it is overcrowded.
I can’t give you a live example of this because I don’t want to wait that long (>__<)
Bit shift
I’ll use a visual demonstration.
Let’s take 13, which usually looks like this
Now let’s shift left by 5
Moving by 5, we have 416 instead of 13
Although 1101 is also suitable for 13, 416 is simply found in a different place in the byte
By performing a bit shift, we ended up changing the decimal value on the output.
How it works in the game
The scheme
Next, the signal goes to the arithmetic combinators, which in our case together play the role of 1 byte or 8 bits
From them, the signal goes to the combinator that divides by the remainder (%) *number* % 2
How display segments/signals work
https://steamcommunity.com/sharedfiles/filedetails/?id=3168628437
I will show you with the following example
Where 1 is a decimal representation and 2 is a bit representation
I take our symbol A into the combinator and shift it by 1
And we got a value with a plus sign.
Let me remind you that the condition for the display lamps to light up is the following “symbol” < 0
However, if you shift it by 2, the value will be minus because segment A should be lit on a two
The decimal value of a “symbol” is a bit code. It contains information about when the signal is positive and when it is negative. That is, thanks to it, small lamps know when they need to work and when not
Blueprint
Install the “Text Plates”[mods.factorio.com] mod to see the characters
Sources/Reference
Bit numbering
https://hmn.wiki/uk/Most_significant_bit
Bit
https://en.wikipedia.org/wiki/Bit
Sign bit
https://en.wikipedia.org/wiki/Sign_bit
Bit to byte
https://citizenmaths.com/ru/data-storage/32-bit-to-byte
Overflow
https://en.wikipedia.org/wiki/Integer_overflow
Bit shift
https://www.wikiwand.com/en/Bitwise_operation
https://www.wikiwand.com/uk/%D0%91%D1%96%D1%82%D0%BE%D0%B2%D0%B8%D0%B9_%D0%B7%D1%81%D1%83%D0%B2
Division with remainder
https://www.wikiwand.com/en/Euclidean_division
Factorio wiki
https://wiki.factorio.com/Arithmetic_combinator/uk
Most significant bit (MSB)
https://www.techtarget.com/whatis/definition/most-significant-bit-or-byte
https://youtu.be/KReHvV2SQj0?si=3UE24uqHKK_ONdYG
Scheme concept
https://youtu.be/KTdvGZfWMX4?si=iMD7NGpLYN9P_XW_
And that wraps up our share on Factorio: DLC Theory, bit, byte, binary shift and other (ENG). If you have any additional insights or tips to contribute, don’t hesitate to drop a comment below. For a more in-depth read, you can refer to the original article here by ♫ SONNYTON ♫, who deserves all the credit. Happy gaming!