Skip to content
Snippets Groups Projects
Commit b96e6d07 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

C-Programme für erweiterte Morse-Tabellen, 30.5.2023

parent dbbf3660
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdint.h>
#include <string.h>
static const char *morse[256] = {
['.'] = ".-.-.-",
[','] = "--..--",
[':'] = "---...",
[';'] = "-.-.-.",
['?'] = "..--..",
['!'] = "-.-.--",
['-'] = "-....-",
['_'] = "..--.-",
['('] = "-.--.",
[')'] = "-.--.-",
['\''] = ".----.",
['='] = "-...-",
['+'] = ".-.-.",
['/'] = "-..-.",
['@'] = ".--.-.",
['"'] = ".-..-.",
[0x02] = "-.-.-", /* Spruchanfang */
[0x03] = ".-.-.", /* Spruchende */
[0x06] = "...-.", /* verstanden */
[0x04] = "...-.-", /* Verkehrsende */
[0x7f] = "........", /* Fehler */
['0'] = "-----",
['1'] = ".----",
['2'] = "..---",
['3'] = "...--",
['4'] = "....-",
['5'] = ".....",
['6'] = "-....",
['7'] = "--...",
['8'] = "---..",
['9'] = "----.",
['A'] = ".-",
['B'] = "-...",
['C'] = "-.-.",
['D'] = "-..",
['E'] = ".",
['F'] = "..-.",
['G'] = "--.",
['H'] = "....",
['I'] = "..",
['J'] = ".---",
['K'] = "-.-",
['L'] = ".-..",
['M'] = "--",
['N'] = "-.",
['O'] = "---",
['P'] = ".--.",
['Q'] = "--.-",
['R'] = ".-.",
['S'] = "...",
['T'] = "-",
['U'] = "..-",
['V'] = "...-",
['W'] = ".--",
['X'] = "-..-",
['Y'] = "-.--",
['Z'] = "--..",
['a'] = ".-",
['b'] = "-...",
['c'] = "-.-.",
['d'] = "-..",
['e'] = ".",
['f'] = "..-.",
['g'] = "--.",
['h'] = "....",
['i'] = "..",
['j'] = ".---",
['k'] = "-.-",
['l'] = ".-..",
['m'] = "--",
['n'] = "-.",
['o'] = "---",
['p'] = ".--.",
['q'] = "--.-",
['r'] = ".-.",
['s'] = "...",
['t'] = "-",
['u'] = "..-",
['v'] = "...-",
['w'] = ".--",
['x'] = "-..-",
['y'] = "-.--",
['z'] = "--.."
};
int main (void)
{
for (int c = 0; c < 128; c++)
{
uint8_t bits = 0;
uint8_t mask = 1;
const char *p = morse[c];
if (p)
{
while (*p)
{
if (*p == '-')
bits |= mask;
mask <<= 1;
p++;
}
}
printf (" 0x%02x,", bits);
}
printf ("\n");
for (int c = 0; c < 128; c++)
{
const char *p = morse[c];
if (p)
printf (" %zu,", strlen (p));
else
printf (" 0,");
}
printf ("\n");
}
#include <stdio.h>
#include <stdint.h>
uint8_t morse_bits[128] =
{
0x00, 0x00, 0x15, 0x0a, 0x28, 0x00, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x35, 0x12, 0x00, 0x00, 0x00, 0x00, 0x1e,
0x0d, 0x2d, 0x00, 0x0a, 0x33, 0x21, 0x2a, 0x09,
0x1f, 0x1e, 0x1c, 0x18, 0x10, 0x00, 0x01, 0x03,
0x07, 0x0f, 0x07, 0x15, 0x00, 0x11, 0x00, 0x0c,
0x16, 0x02, 0x01, 0x05, 0x01, 0x00, 0x04, 0x03,
0x00, 0x00, 0x0e, 0x05, 0x02, 0x03, 0x01, 0x07,
0x06, 0x0b, 0x02, 0x00, 0x01, 0x04, 0x08, 0x06,
0x09, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x2c,
0x00, 0x02, 0x01, 0x05, 0x01, 0x00, 0x04, 0x03,
0x00, 0x00, 0x0e, 0x05, 0x02, 0x03, 0x01, 0x07,
0x06, 0x0b, 0x02, 0x00, 0x01, 0x04, 0x08, 0x06,
0x09, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00
};
uint8_t morse_length[128] =
{
0, 0, 5, 5, 6, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 6, 6, 0, 0, 0, 0, 6, 5, 6, 0, 5, 6, 6, 6, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 0, 5, 0, 6,
6, 2, 4, 4, 3, 1, 4, 3, 4, 2, 4, 3, 4, 2, 2, 3,
4, 4, 3, 3, 1, 3, 4, 3, 4, 4, 4, 0, 0, 0, 0, 6,
0, 2, 4, 4, 3, 1, 4, 3, 4, 2, 4, 3, 4, 2, 2, 3,
4, 4, 3, 3, 1, 3, 4, 3, 4, 4, 4, 0, 0, 0, 0, 8
};
int main (void)
{
for (int c = 0; c < 128; c++)
if (morse_length[c])
{
printf (" ['%c'] = \"", c);
uint8_t bits = morse_bits[c];
uint8_t mask = 1;
int l = morse_length[c];
for (int i = 0; i < l; i++)
{
if (bits & mask)
printf ("-");
else
printf (".");
mask <<= 1;
}
printf ("\",\n");
}
return 0;
}
[''] = "-.-.-",
[''] = ".-.-.",
[''] = "...-.-",
[''] = "...-.",
['!'] = "-.-.--",
['"'] = ".-..-.",
['''] = ".----.",
['('] = "-.--.",
[')'] = "-.--.-",
['+'] = ".-.-.",
[','] = "--..--",
['-'] = "-....-",
['.'] = ".-.-.-",
['/'] = "-..-.",
['0'] = "-----",
['1'] = ".----",
['2'] = "..---",
['3'] = "...--",
['4'] = "....-",
['5'] = ".....",
['6'] = "-....",
['7'] = "--...",
['8'] = "---..",
['9'] = "----.",
[':'] = "---...",
[';'] = "-.-.-.",
['='] = "-...-",
['?'] = "..--..",
['@'] = ".--.-.",
['A'] = ".-",
['B'] = "-...",
['C'] = "-.-.",
['D'] = "-..",
['E'] = ".",
['F'] = "..-.",
['G'] = "--.",
['H'] = "....",
['I'] = "..",
['J'] = ".---",
['K'] = "-.-",
['L'] = ".-..",
['M'] = "--",
['N'] = "-.",
['O'] = "---",
['P'] = ".--.",
['Q'] = "--.-",
['R'] = ".-.",
['S'] = "...",
['T'] = "-",
['U'] = "..-",
['V'] = "...-",
['W'] = ".--",
['X'] = "-..-",
['Y'] = "-.--",
['Z'] = "--..",
['_'] = "..--.-",
['a'] = ".-",
['b'] = "-...",
['c'] = "-.-.",
['d'] = "-..",
['e'] = ".",
['f'] = "..-.",
['g'] = "--.",
['h'] = "....",
['i'] = "..",
['j'] = ".---",
['k'] = "-.-",
['l'] = ".-..",
['m'] = "--",
['n'] = "-.",
['o'] = "---",
['p'] = ".--.",
['q'] = "--.-",
['r'] = ".-.",
['s'] = "...",
['t'] = "-",
['u'] = "..-",
['v'] = "...-",
['w'] = ".--",
['x'] = "-..-",
['y'] = "-.--",
['z'] = "--..",
[''] = "........",
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment