How to implement Baudot encoding


I'm trying to implement a <a href="http://en.wikipedia.org/wiki/Baudot_code" rel="nofollow">Baudot character encoding</a> (a 6 bit per character code) in .Net. It's for a <a href="https://www.cospas-sarsat.org/" rel="nofollow">Cospas Sarsat device</a>.

I've started by deriving from the Encoding class:

public class BaudotEncoding : Encoding {

I'm looking for a simple, efficient way to implement a bidirectional character map (the map can be readonly):

Dictionary<char, int> CharacterMap = new Dictionary<char, int> { { ' ', 0x100100 }, { '-', 0x011000 }, { '/', 0x010111 }, { '0', 0x001101 }, { '1', 0x011101 }, { '2', 0x011001 }, ... }

I also need to figure out how to implement the GetBytes method of System.Text.Encoding

public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) {

I am having trouble figuring out how to implement this method because the characters don't fit in nice 8 bit sets.


Simple string constants may be sufficient for the mapping of chars to int values, and possibly faster than Dictionary. This quickly thrown together code shows the idea of what I was describing in <a href="https://stackoverflow.com/questions/22566845/is-there-a-built-in-type-for-a-lookup-reverse-lookup-table" rel="nofollow">your previous question</a>. I don't know how you want to handle the figures/letters issue, and you'd want to add range checking on arguments. You'll also need to test for correctness. But it shows the idea of just putting the char values in a string and using that to look up in both directions. Given an int value, it will be as fast as you can get. Given a char to do the reverse lookup will, I expect, be extremely fast as well.

public class Baudot { public const char Null = 'n'; public const char ShiftToFigures = 'f'; public const char ShiftToLetters = 'l'; public const char Undefined = 'u'; public const char Wru = 'w'; public const char Bell = 'b'; private const string Letters = "nE\nA SIU\rDRJNFCKTZLWHYPQOBGfMXVu"; private const string Figures = "n3\n- b87\rw4',!:(5\")2#6019?&u./;l"; public static char? GetFigure(int key) { char? c = Figures[key]; return (c != Undefined) ? c : null; } public static int? GetFigure(char c) { int? i = Figures.IndexOf(c); return (i >= 0) ? i : null; } public static char? GetLetter(int key) { char? c = Letters[key]; return (c != Undefined) ? c : null; } public static int? GetLetter(char c) { int? i = Letters.IndexOf(c); return (i >= 0) ? i : null; } }

You will also probably want to modify the simple handling of special characters I define as constants. For example, using char(0) for null, ASCII bell for bell (if there is such a thing). I just threw in quick lowercase letters for demonstration purposes.

I used nullable return values to demonstrate the notion of not finding something. But it might be simpler to just return the Undefined constant if a given int value does not map to anything, and -1 if the given char is not in the Baudot character set.


  • im counting the number of characters in a file but i want to count the number of words that are less
  • SQL Server 2008 : input a comma delimited list?
  • Extract last name, first name and suffix into separate columns
  • How can I get the almost last substring from “/” delimited string in T-SQL?
  • PHP base64_decode C# equivalent
  • How to separate (split) string with comma in SQL Server stored procedure
  • EMACS rebinding C-spc disable highlight of selected region
  • Int to char conversion rule in C when int is outside the range of char
  • Implementing an abstract function with access types in Ada
  • undefined reference error due to use of static variables [duplicate]
  • Time taken for Hadoop job to execute
  • In java, how do you retrieve images from a jar file?
  • Fire callback when selection was made with select2 4.0, and retrieve the value of last selection
  • How to use the resource module to measure the running time of a function?
  • possible limitation of implode function in PHP
  • Xamarin PCLCrypto SHA256 give different hash
  • c++ using primitive types as a base class
  • Accessing the variables from a PHP Anonymous Function
  • ASPNetCore MVC Routing Let Server Handle Specific Route
  • Lua: Line breaks in strings
  • Perspective projection, 4 points
  • Available space left on drive - WinAPI - Windows CE
  • cell spacing in div table
  • XSLT foreach repeating nodes to flat
  • How to create a 2D image by rotating 1D vector of numbers around its center element?
  • Getting NullPointer exception with File.listfiles()
  • How can I include If-None-Match header in HttpRequestMessage
  • Simple linked list-C
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • Can I read an iPhone beacon with Windows.Devices.Bluetooth.Advertisement.BluetoothLEManufacturerData
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • copying resource to sdcard gives a damaged file in android
  • Spark fat jar to run multiple versions on YARN
  • JFileChooser in front of fullscreen Swing application
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • Large data - storage and query
  • How do you troubleshoot character encoding problems?
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • failed to connect to specific WiFi in android programmatically