Code64 is a 6-bit representation of 8-bit ASCII values. A byte is defined as 8 bits. Each of 256 different possible byte values may represent part of alphabetic, numeric (integer and decimal of varying internal sizes), or special characters whereas each of the 64 different 6-bit results always represent alphabetic (upper or lower case), numeric (number 0-9), or two special characters, '+', and '/' according to their position in the Code64 translation table. Note that the 6-bit Code64 characters are stored as 8-bit printable bytes for importing and exporting.
Four Code64 8-bit bytes are required for every three bytes of 8-bit binary data to be translated because each Code64 byte only contains 6 bits of the original binary data. The Code64 Open Standard mandates that the special character '=' be used to pad the ASCII printable resultant byte stream so that its length is a multiple of four.
Note that there are 64 entries where entry 0 is 'A' and entry 63 (in binary form 11 1111) is the code for '/'.
Example: The four-byte Code64 stream 'SGFs' becomes 'Hal' when converted into 8-bit binary. The bits of each byte are split into two groups to simplify viewing.
'Hal' in 8-bit binary is
0100 0100 0110 0001 0110 1100and when spliced into 6-bit blocks for encoding becomes
01 0001 00 0110 00 0101 10 1100
The ASCII to Code64 translation table is used to translate each of the four 6-bit groups resulting in 'SGFs'. The entry index for translating the fourth Code64 block 10 1100 (44 decimal) into printable ASCII is 's', the 45th entry in the Code64 Table. Note that the positional value of an entry is its code index + 1.
Similarly each of the four Code64 6-bit characters stored in an 8-bit byte can be stitched back into three 8-bit bytes by omitting the extra two bits of each Code64 8-bit byte.
Translation Tables:
Code64 0 63
| |
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
Code64 ASCII
00 0000 -> A <- 0100 0001
00 0001 -> B <- 0100 0010
. . .
01 1001 -> Z <- 0101 1010
01 1010 -> a <- 0110 0001
. . .
11 0011 -> z <-
11 0100 -> 0 <- 0110 0000
. . .
11 1101 -> 9 <- 0110 1001
11 1110 -> + <- 0010 1011
11 1111 -> / <- 0010 1111
= <- 0011 1101
Cribbage Game Format:
software encoder origin: 16 bytes 128 bits
cribbage program name: 16 bytes 128 bits
name of player 0: 8 bytes 64 bits
name of player 1: 8 bytes 64 bits
comments 18 bytes 144 bits
date of game:
year 2 bytes 12 bits
month 1 byte 4 bits
day 1 byte 5 bits
hour 1 byte 6 bits
minute 1 byte 6 bits
second 1 byte 6 bits
number of games 1 byte 8 bits
number of deals: 1 bytes 8 bits
n = 0000 0111 (7) means 8 deals
maximum of 256 (n + 1) X 150 bits
On average each game is 10 deals
A session of 25 games can be recorded
Cribbage Deal Format:
player 0 hand 4 bytes 24 bits
player 1 hand 4 bytes 24 bits
crib 4 bytes
player 0 discards 2 bytes 12 bits
player 1 discards 2 bytes 12 bits
starter 1 byte 6 bits
pegging plays 8 bytes 56 bits
player 0 score 1 byte 7 bits
player 1 score 1 byte 7 bits
flags 1 byte
dealer flag 0000 000d 1 bit
last deal flag 00f0 0000 1 bit
---------
150 bits
each hand has four cards
each card is 6 bits
each pegging card in order of occurrence is 7 bits
scores after pegging - 7 bits maximum is 0111 1001 (121)
d = 0 or 1 - player number
f = 1 if the deal is the last of game, 0 otherwise
Cribbage Card Format: 00ss rrrr:
ss is suit:
00 = spades
01 = hearts
10 = diamonds
11 = clubs
rrrr is rank:
0001 = Ace
0010 = 2
. . .
1010 = 10
1011 = Jack
1100 = Queen
1101 = King
Cribbage Pegging Card Format: 0pss rrrr:
p is player number:
0 = player 0
1 = player 1
example:
0011 1101 King of Clubs starter, card for either player
0011 1101 King of Clubs by player 0 pegging play
0111 1101 King of Clubs by player 1 pegging play
If a game ends during pegging, then the remaining pegging plays, if any, are represented as 0111 1111.
A Cribbage game saved in Code64 implementation as described above can be imported and viewed as a "Movie" in HALSCRIB CLX version 1.0. The movie will show the initial cards for each player. A mouse click on the table will then show the discards, pegging plays, and scores. The rest of the game can be viewed by a series of mouse clicks until there are no more deals. If the game ends as a result of pegging before the 8th card, then the remaining cards are not displayed.
HALSCRIB CLX v1.0 can export a game played between a user and 'HAL', the computer opponent in Code64 format which can then be used by any software that implements the above Open Code64 Implementation of a Cribbage Game.
E-mail me for comments, criticism, discussion, feedback, omissions, suggestions.