Ok so I just implemented this myself and noticed that counting nulls as different values is not ANSI compliant. The ANSI compliant way of encoding would be:
Note that the columns are concatenated with an empty string to get implicit conversion. NULL is encoded as '\0' and empty strings are encoded as '\0' + element number. This should produce collision free strings as long as the column values don't contain the '\0' character.