How to convert int and char variables into 6bits ASCII table character line ?

Hi everybody, I'm new on arduino and programming.

As a sailor, I use navigation softs and I would like to display some infos on the sailing softs from a acoustic beacon.

To do so, I get the value from the beacon in the form of PTSAG trames (GPS type trames). After treating theses trames, I get the position in lattitude and longitude coordinates, that I want to use to display the position of the beacon on the navigation soft.

From these information, and some other, I build a TLL trames, readable on most of the softwares by using another soft that I would like to avoid.

To read the position on the softs, I have to translate these informations in a special trame format, AIS trames. Which is the standard communication protocol on sea to avoid obstacles and repair other ships.
AIS i.e : !AIVDM,1,1,,A,14VE:80029hn1qmIe3Pjrj00SF,0*3A
The informations of the MMSI number, position, and etc are converted into binary numbers, and compressed using a 6-bits ASCII tables.

I would like to know a way to convert for instance a MMSI from dec to binary and then to compress it using this ASCII table.
i.e the MMSI is: 228136000, I should be able to convert it in a 30bits binary and to convert it from the ASCII table.

Thanks for your help, don't hesitate if I am not understandable in my descriptions specially for the AIS trame model.

Vincent

PS: Here is the norm for the braves: http://www.itu.int/dms_pubrec/itu-r/rec/m/R-REC-M.1371-4-201004-I!!PDF-E.pdf (I invite you to jump to page 77 at chapter 3.5 AIS Inforrmation

The first step in your quest is to make an array representing the ASCII characters. Unfortunately this isn't a direct 1:1 (+ offset) relationship between the actual ASCII table and the binary values, so a lookup table (LUT) will be needed.

This may be as simple as:

char *LUT="@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_ !\"#$%&`()*+,-./0123456789:;<=>?";

Each character in that string can be represented as a number 0-63, for instance, LUT[4] equals D.

How you then convert your data into 6-bit values to map to that table (and/or back again) depends on a) what format the data is in, and b) what format AIS expects it to be in.

For instance, if you have an unsigned integer value 12345, that is stored internally as 16 bits. If AIS expects that as raw 16-bit data, then it is a case of taking each 6 bits in turn and mapping them. If it expects the individual digits as individual 6-bit values, then you may be better off printing the value to a string, including any leading zeros or padding, and then work on it a character at a time from there.

If your frames are of a fixed format and length, then it may be worth setting up a union / structure to access the 6-bit values. For instance, if you have a frame that is 24 bits in length (4 groups of 6 bits) it may be good to map them as:

struct ais24 {
  union {
    char data[3]; // Storage for 24 bits
    struct {
      unsigned bg0:6;
      unsigned bg1:6;
      unsigned bg2:6;
      unsigned bg3:6;
    } __attribute__((packed));
  } __attribute__((packed));
} __attribute__((packed));

struct ais24 myData;

Then you can access myData.data[0 .. 2] as bytes, and myData.bg0 .. myData.bg6 as the same data in 6 bit blocks.