Pardon the "double post" as it were. I was handily informed the
mailing list strips attachments.
Therefore, for those interested, here's text versions of the header
file (rad50.h) and the actual C that does the RADIX-50 conversions
(rad50.c):
/* ========================================================================== */
#ifndef _RAD50_H
#define _RAD50_H
#include <stdint.h>
int rad50enc(const char *, uint16_t *);
int rad50dec(uint16_t, char *);
int xrad50enc(const char *, uint32_t *);
int xrad50dec(uint32_t, char *);
#endif /* _RAD50_H */
/* ========================================================================== */
/*
* Copyright (c) 2019 C. Gauger-Cosgrove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <ctype.h>
#include <string.h>
#include "rad50.h"
#define RAD50TAB " ABCDEFGHIJKLMNOPQRSTUVWXYZ$.*0123456789"
int
rad50enc(const char *text, uint16_t *value) {
size_t i;
uint16_t t;
const int mult[3] = {1600, 40, 1};
char *c;
if (strlen(text) == 0) {
*value = 0;
return 0;
} else if (strlen(text) > 3) {
*value = 0xFFFF;
return 1;
}
t = 0;
for (i = 0; i < strlen(text); ++i) {
c = (char *) strchr(RAD50TAB, toupper(text[i]));
if (c == NULL) {
*value = 0xFFFF;
return 1;
}
t += (c - RAD50TAB) * mult[i];
}
*value = t;
return 0;
}
int
rad50dec(uint16_t value, char *text) {
size_t i;
const int mult[3] = {1600, 40, 1};
if (value >= 0xFA00) {
text[0] = 0;
return 1;
}
for (i = 0; i < 3; ++i)
text[i] = RAD50TAB[(value / mult[i]) % 40];
text[3] = 0;
return 0;
}
int
xrad50enc(const char *text, uint32_t *value) {
size_t i;
uint32_t t;
const int mult[6] = {102400000, 2560000, 64000, 1600, 40, 1};
char *c;
if (strlen(text) == 0) {
*value = 0;
return 0;
} else if (strlen(text) > 6) {
*value = 0xFFFFFFFF;
return 1;
}
t = 0;
for (i = 0; i < strlen(text); ++i) {
c = (char *) strchr(RAD50TAB, toupper(text[i]));
if (c == NULL) {
*value = 0xFFFFFFFF;
return 1;
}
t += (c - RAD50TAB) * mult[i];
}
*value = t;
return 0;
}
int
xrad50dec(uint32_t value, char *text) {
size_t i;
const int mult[6] = {102400000, 2560000, 64000, 1600, 40, 1};
if (value >= 0xF4240000) {
text[0] = 0;
return 1;
}
for (i = 0; i < 6; ++i)
text[i] = RAD50TAB[(value / mult[i]) % 40];
text[6] = 0;
return 0;
}
/* ========================================================================== */
Best regards,
Christian Gauger-Cosgrove
On 19/11/2019, Christian Gauger-Cosgrove <[email protected]> wrote:
> On 19/11/2019, Dominique Devienne <[email protected]> wrote:
>> On Tue, Nov 19, 2019 at 2:00 AM Peter da Silva <[email protected]> wrote:
>>> The return of RADIX-50.
>>>
>>> https://en.wikipedia.org/wiki/DEC_Radix-50
>>
>> Thanks! I might go with this going forward. --DD
>>
> To make life easier for those desiring to experience the Wonders of
> RADIX-50™, if anyone wants I've attached a copy of my implementation
> of RAD50 in both the "traditional" 16-bit form, and a 32-bit form.
>
> The "*enc" functions encode a string into RAD50, and the "*dec"
> functions decode. "rad50*" works on a 16-bit value, "xrad50*" on a
> 32-bit.
>
> I leave it as an exercise for the reader to implement a 64-bit function.
>
> If anyone has ideas of how to improve the functions: Please feel free
> to contribute.
>
> Best regards,
> Christian
> --
> Christian M. Gauger-Cosgrove
> STCKON08DS0
> Contact information available upon request.
>
--
Christian M. Gauger-Cosgrove
STCKON08DS0
Contact information available upon request.
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users