## uuencode, did I get it right?

9 posts / 0 new
Author
Message

I didn't see any example function for doing 3 in 4 out uuencoding but it seem simple enough, does it look right?

unsigned char a = 1;
unsigned char b = 2;
unsigned char c = 4;

unsigned char d = 0;
unsigned char e = 0;
unsigned char f = 0;
unsigned char g = 0;

d = (a & 0xfc)>>2;
e = ( (a & 0x3)<<4 | (b & 0xf0)>>4 ) ;
f = ( (b & 0x0f) <<2) | (c & 0xc0)>>6;
g = (c & 0x3f);

printf("d,e,f,g:  %i,%i,%i,%i", d,e,f,g);

`d,e,f,g:  0,16,8,4`
Last Edited: Tue. Jun 18, 2019 - 03:20 PM

S_K_U_N_X wrote:
I didn't see any example function
I just googled "uuendcode algorithm c source" and it hits lots of links. Some of those (at the heart) use things like:

```		uue_char[0] = ((byte_to_encode[0] >> 2) & 0x3f);
uue_char[1] = (((byte_to_encode[0] << 4) | ((byte_to_encode[1] >> 4) & 0x0f)) & 0x3f);
uue_char[2] = (((byte_to_encode[1] << 2) | ((byte_to_encode[2] >> 6) & 0x03)) & 0x3f);
uue_char[3] = (byte_to_encode[2] & 0x3f);```
```     c1 = *p >> 2;
c2 = (*p << 4) & 060 | (p[1] >> 4) & 017;
c3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
c4 = p[2] & 077;
```
```	  ch = *p >> 2;
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
ch = ((*p << 4) & 060) | ((p[1] >> 4) & 017);
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
ch = ((p[1] << 2) & 074) | ((p[2] >> 6) & 03);
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
ch = p[2] & 077;
ch = ENC (ch);
if (putchar (ch) == EOF)
break;```

So, yeah, it seems like you are on the right lines

(but as there are so many existing implementations I wonder if it's worth reinventing the wheel?)

PS octal constants? really ?

Last Edited: Tue. Jun 18, 2019 - 04:04 PM

PS octal constants? really ?

Hey I just threw together some test code, come'on man, cut me some slack.

I didn't fine much other then converting an entire document but sure ill use those, why not. Thx.

Last Edited: Tue. Jun 18, 2019 - 04:30 PM

I'm not talking about your code. I'm talking about some of the examples I quoted. They are using octal constants. I don't know how any programmer can visualize 3 bits at a time. With hex it's neat 4 bit groups.

Last Edited: Tue. Jun 18, 2019 - 05:13 PM

clawson wrote:
I don't know how any programmer can visualize 3 bits at a time. With hex it's neat 4 bit groups.

I guess it depends on how many 18/36 bit systems (PDP-10, DECSYSTEM-20) you have programmed!

Jim

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

How wow, I didn't even see that.. Yeah that is how my colleague does it. He never writes in hex always decimal but in his defense he does not know what hex really is, he thinks it's something you convert to.  So funny when he says, ok, great now how to I convert this to HEX so it sends it down the UART right........

How do you convert to hex.. ?

Yeah what is 130 in hex,

its 130....or shown  as 0x82 or 0b10000010 but it's all the same value.... Then he walks away like I told him his dog died.

Last Edited: Tue. Jun 18, 2019 - 06:17 PM