uuencode, did I get it right?

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

    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
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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! smiley 

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The 8080 had an instruction set that encoded beautifully in octal. So did the pdp11. And then everyone started using hex to save a character of typing... :-(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe it's just me. If I see a constant like 060 I can't immediately visualize which bits that is. I guess its 00 110 000 but even writing it in three groupings like that I still can't see it. But was soon as you write 0011 0000 (0x30) then it become instantly apparent this is picking out the lower two bit of the upper nibble. (and yeah some of my early work at Uni was with PDP11 in Asm so I remember it well!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess it depends on whether you’re trying to pick out bits, or bit fields. Pdp11 and 8080 had very distinct 3bit fields, so if printed in octal you could practically do disassembly in your head. But picking out bit 5 would be tougher.