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

C-Programme für Morse-Tabellen, 30.5.2023

parent 1d5acb26
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] = {
['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, 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, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1f, 0x1e, 0x1c, 0x18, 0x10, 0x00, 0x01, 0x03,
0x07, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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,
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, 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, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0,
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, 0,
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, 0
};
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 (".");
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