<p>That is a checksum. It's added by the host software to the G-code, to allow some basic verification by the firmware that the G-code was transmitted unchanged. It doesn't change the meaning of the G-code, and what your sequence actually represents is just <code>M106, G28, M107</code>. The <code>N0,N1,N2,...</code> are line numbers, and the combination of line numbers and checksums is used to request a re-send of any lines that were corrupted during transmission.</p>

CC BY-SA 3.0
2016-12-02T14:30:28.140Z
Do you happen to know the checksum algorithm used here?
Carl Witthoft
CC BY-SA 3.0
2016-12-02T15:33:00.783Z
In Marlin, all the bytes for the individual characters are XOR-ed together, and the result should be the same as the checksum.
Tom van der Zanden
CC BY-SA 3.0
2016-12-04T00:17:49.473Z
Just XOR: `byte checksum = 0;
        byte count = 0;
        while(instruction[count] != '*')
                checksum = checksum^instruction[count++];`
Mtl Dev
CC BY-SA 3.0
2016-12-02T08:11:42.747Z
2016-12-02T08:11:42.747Z
Tom van der Zanden
<p>Doing some low level monitoring, the following sequence is sent to the printer:</p>

<pre><code>N0 M106*36 
N1 G28*18 
N2 M107*39
</code></pre>

<p>This sequence just turns the fan on, homes the printer, then turns the fan off.</p>

<p>Question: What is the purpose of the asterix/star/(*) and the two succeeding digits on each line?</p>

CC BY-SA 4.0
2019-09-25T10:33:40.843Z
* asterisk - [Asterix](https://en.wikipedia.org/wiki/Asterix) is a character in a cartoon series.
Andrew Morton
CC BY-SA 4.0
2019-09-25T14:43:04.720Z
@AndrewMorton So that would make the gcode the Romans then - with Asterix being their checksum, stopping corruption in his local area?
Mtl Dev
CC BY-SA 4.0
2019-09-25T14:46:03.363Z
Hmmm... maybe. The Romans did build a lot of things, like a 3-d printer does.
Andrew Morton
<g-code>
What is the purpose of asterix (*) in Gcode?
Mtl Dev
# What is the purpose of asterix (*) in Gcode?

(Asked by: username_0 on 2016-12-01)

Doing some low level monitoring, the following sequence is sent to the printer:

```
N0 M106*36 
N1 G28*18 
N2 M107*39

```

This sequence just turns the fan on, homes the printer, then turns the fan off.

Question: What is the purpose of the asterix/star/(\*) and the two succeeding digits on each line?

**Tags:** g-code

> **Comments:**
> **username_1**: * asterisk - [Asterix](https://en.wikipedia.org/wiki/Asterix) is a character in a cartoon series.  
> **username_0**: @username_1 So that would make the gcode the Romans then - with Asterix being their checksum, stopping corruption in his local area?  
> **username_1**: Hmmm... maybe. The Romans did build a lot of things, like a 3-d printer does.  

---

## 1 answers

### Answer by username_2 on 2016-12-02. Score: 14 | Accepted answer

That is a checksum. It's added by the host software to the G-code, to allow some basic verification by the firmware that the G-code was transmitted unchanged. It doesn't change the meaning of the G-code, and what your sequence actually represents is just `M106, G28, M107`. The `N0,N1,N2,...` are line numbers, and the combination of line numbers and checksums is used to request a re-send of any lines that were corrupted during transmission.

> **Comments:**
> **username_3**: Do you happen to know the checksum algorithm used here?  
> **username_2**: In Marlin, all the bytes for the individual characters are XOR-ed together, and the result should be the same as the checksum.  
> **username_0**: Just XOR: `byte checksum = 0;         byte count = 0;         while(instruction[count] != '*')                 checksum = checksum^instruction[count++];`  

---

