Factorio

Factorio

Not enough ratings
Display theory, bit, byte, binary shift and other (ENG)
By ※RED※SKULL※
The first source is written in Ukrainian. And the translation was done with the help of Deepl

Information that wasn't in the display creation manual.
I didn't include it there, and I didn't even want to, because this topic is a completely different science. It requires not only a desire to play Factorio, but also an understanding of how the processor works, math, and maybe even programming

It's not enough information for one evening, so consider it a lecture for the game. I will say that I was even shocked by half of the terms, especially by their "macaroni" nature. To tell you about one, you need two more, and you need a separate section to tell them

I do not have any awards that can confirm my knowledge/competence in this topic. Therefore, if you find an incorrect interpretation of the term or incorrect information. Just write about it in the comments
   
Award
Favorite
Favorited
Unfavorite
Bit & byte
Bit - (8, 16, 24, 32....) the minimum amount of information represented in the binary system. 1 or 0 symbolizes the status (on/off)

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
How to get 13 in 1101? ¯\_(ツ)_/¯

To convert ordinary 13 to binary, use the division operation with the remainder



Thus, the binary representation of 13 is 1101



What does the "rule of converting a decimal number to binary" sound like?

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)
Sign bit. The leftmost bit in the number indicates the sign for a decimal number

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
A Factorio is written in 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



The reason for this is an overflow and this is what it sounds like

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



Warning
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
Bit shift is the movement of bits in a binary number to the left or right. When a bit goes outside the number, it is lost, and new bits fill the empty spaces



I'll use a visual demonstration.
Let's take 13, which usually looks like this
Here, the bit shift is 1



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

https://youtu.be/fHAFPdr4fiU?si=L1X35fRtSTcCs2wt
The scheme
In the constant combinator, data/values are set, then they get into the combinator that controls the bit shift: by the values 1,2,3..... and the direction to the right (>>) or left (<<)



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
Take a display from the guide

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



My vision/explanation

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
Here is a 32-bit schematic and several ready-made display options

Install the "Text Plates"[mods.factorio.com] mod to see the characters

https://factoriobin.com/post/8iUNMTDm



3 Comments
scibee1 Oct 13, 2024 @ 4:09pm 
I thought that this was a collection of theories about the upcoming space age DLC, but this is far more interesting.
※RED※SKULL※  [author] Mar 13, 2024 @ 2:43am 
In fact, it's 4. The reason is in this scheme. If I shift to 0, then the signal did not go and to display it classically, you need to remove the arithmetic combiner from the circuit (which I indicated with yellow) and connect a constant to the circuit. However, then you would not have control over the bit shift, you would have to change the decimal values in the constant combinator. Therefore, I set the default to 1 and then the green is displayed
Absinthe-Bot Mar 12, 2024 @ 10:57pm 
In your << 5, isn't the in game example actually a shift of 4 as it shifts the green light over to the left 4 times?