bit_read_UMC (Bit_Chain *dat)
{
  int i, j;
  // eg handle FD485E65F
  #define MAX_BYTE_UMC 6
  unsigned char byte[MAX_BYTE_UMC];
  BITCODE_UMC result;

  result = 0;
  for (i = MAX_BYTE_UMC-1, j = 0; i >= 0; i--, j += 7)
    {
      byte[i] = bit_read_RC (dat);
      if (!(byte[i] & 0x80))
        {
          result |= (((BITCODE_UMC)byte[i]) << j);
          return result;
        }
      else
        byte[i] &= 0x7f;

      result |= ((BITCODE_UMC)byte[i]) << j;
    }

  loglevel = dat->opts & DWG_OPTS_LOGLEVEL;
  LOG_ERROR (
      "bit_read_UMC: error parsing modular char, i=%d,j=%d,result=0x%lx", i, j,
      result)
  LOG_HANDLE ("  @%lu.%u: [0x%x 0x%x 0x%x 0x%x 0x%x]\n", dat->byte - 5,
            dat->bit, dat->chain[dat->byte - 5], dat->chain[dat->byte - 4],
            dat->chain[dat->byte - 3], dat->chain[dat->byte - 2],
            dat->chain[dat->byte - 1])
  return 0; /* error... */
}
bit_read_UMC (Bit_Chain *dat)
{
  int i, j;
   
  #define MAX_BYTE_UMC 6
  unsigned char byte[MAX_BYTE_UMC];
  BITCODE_UMC result;

  result = 0;
  for (i = MAX_BYTE_UMC-1, j = 0; i >= 0; i--, j += 7)
    {
      byte[i] = bit_read_RC (dat);
      if (!(byte[i] & 0x80))
        {
          result |= (((BITCODE_UMC)byte[i]) << j);
          return result;
        }
      else
        byte[i] &= 0x7f;

      result |= ((BITCODE_UMC)byte[i]) << j;
    }

  loglevel = dat->opts & DWG_OPTS_LOGLEVEL;
  LOG_ERROR (
      "bit_read_UMC: error parsing modular char, i=%d,j=%d,result=0x%lx", i, j,
      result)
  LOG_HANDLE ("  @%lu.%u: [0x%x 0x%x 0x%x 0x%x 0x%x]\n", dat->byte - 5,
            dat->bit, dat->chain[dat->byte - 5], dat->chain[dat->byte - 4],
            dat->chain[dat->byte - 3], dat->chain[dat->byte - 2],
            dat->chain[dat->byte - 1])
  return 0;  
}