A squawk code is essentially no more than a sequence of 12 binary digits (bits), each of which can have one of 2 values: 0 (off) or 1 (on).
It's purely for convenience that the 12 bits are customarily divided into 4 groups of 3, to make it easier for us humans to remember them. Three bits make one octal digit (because 8 is 2 to the power of 3).
Incidentally, the Americans do the same trick with the ICAO 24-bit aircraft address that's also used in a transponder, splitting them into 8 groups of 3 bits, i.e. 8 octal digits. Most other countries choose to use groups of 4 bits (hexadecimal digits) since that way you end up with a 6-digit code that's easier to remember than an 8-digit one.