Advertisement
Guest User

7bit

a guest
Apr 16th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. /* Encode 7-bit ASCII data into the buffer out[], which must be at least
  2. ** "len" bytes in length.  The encoded data will have the same size as
  3. ** the decoded data.  You must append a 0 byte to terminate the string.
  4. ** The buffers in[] and out[] may be the same. Call this function again
  5. ** to decode. Return the length encoded, or -1 on error.
  6. */
  7. int ascii7enc(char *out, const char *in, int len)
  8. {
  9.   int ct = len;
  10.   if (!in || !out || len < 0) return -1;
  11.  
  12.   while (ct-- > 0)
  13.   {
  14.     char ch = (*in == 0 || *in == '\'' || *in == 0x80 || *in == '\''^0x80)?
  15.      (*in++ ^ 0x80): *in++;
  16.     *out++ = ch;
  17.   }
  18.  
  19.   return len;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement