A 'bit' is 0 or 1 and is a contraction of the phrase Binary Digit. A byte is defined as 8 bits. Base64 is a 6-bit printable representation for a stream of byte values (ASCII or EBCDIC) which represent data that may be 'graphic' (alphabetic, numeric, special) or 'control' (internal system codes). Each of 256 different possible byte values may represent part of alphabetic, numeric (integer and decimal of varying internal sizes), special (punctuation, '+', '-', etc) or non-printable control characters (CR, DEL, ESC, FF, ... keys and codes) 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 Base64 translation table. Note that the 6-bit Base64 characters are stored into 8-bit printable bytes for transmission (importing and exporting).
Four Base64 8-bit bytes are required for every three bytes of 8-bit binary data to be translated because each Base64 byte only contains 6 bits of the original binary data. The Base64 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 the capital letter'A' and entry 63 (in binary form 11 1111) is the code for a slash '/'.
Example: The four-byte Base64 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 1100when spliced into 6-bit blocks for encoding becomes
01 0001 00 0110 00 0101 10 1100
The ASCII to Base64 translation table is used to translate each of the four 6-bit groups resulting in 'SGFs'. The entry index for translating the fourth Base64 block 10 1100 (44 decimal) into printable ASCII is 's', the 45th entry in the Base64 Table. Note that the positional value of an entry is its code index + 1.
Similarly each of the four Base64 6-bit characters stored in an 8-bit byte can be stitched back into three 8-bit bytes by disregarding the leading two bits of each Base64 8-bit byte.
Translation Tables:
Base64 0 63
| |
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
Base64 ASCII
00 0000 -> A <- 0100 0001
00 0001 -> B <- 0100 0010
. . .
01 1001 -> Z <- 0101 1010
01 1010 -> a <- 0110 0001
. . . . . .
11 0011 -> z <- 0111 1010
11 0100 -> 0 <- 0110 0000
. . .
11 1101 -> 9 <- 0110 1001
11 1110 -> + <- 0010 1011
11 1111 -> / <- 0010 1111
= <- 0011 1101
Cribbage Game Format:
software author/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 byte 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 limit 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 Base64 implementation as described above can be imported and viewed as a "Movie" in HALSCRIB. 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 a game ends as a result of pegging, then the remaining cards, if any, are not displayed.
HALSCRIB can export a game played between you and 'HAL', your opponent in Base64 format which can then be used by any software that implements the above Open Base64 Implementation of a Cribbage Game.
E-mail me for comments, criticism, discussion, feedback, omissions, suggestions.