bit_write_H (Bit_Chain *restrict dat, Dwg_Handle *restrict handle)
{
  int i;
  unsigned char *val;
  unsigned char size;

  if (!handle)
    {
      bit_write_RC (dat, 0);
      return;
    }
  if (handle->value == 0)
    {
      bit_write_RC (dat, handle->code << 4);
      return;
    }

  // TODO: little-endian only. support sizes <= 8, not just 4
  memset (&val, 0, sizeof(val));
  val = (unsigned char *)&handle->value;
  for (i = sizeof(val) - 1; i >= 0; i--)
    if (val[i])
      break;

  size = handle->code << 4;
  size |= i + 1;
  bit_write_RC (dat, size);

  for (; i >= 0; i--)
    bit_write_RC (dat, val[i]);
}
bit_write_H (Bit_Chain *restrict dat, Dwg_Handle *restrict handle)
{
  int i;
  unsigned char *val;
  unsigned char size;

  if (!handle)
    {
      bit_write_RC (dat, 0);
      return;
    }
  if (handle->value == 0)
    {
      bit_write_RC (dat, handle->code << 4);
      return;
    }

   
  memset (&val, 0, sizeof(val));
  val = (unsigned char *)&handle->value;
  for (i = sizeof(val) - 1; i >= 0; i--)
    if (val[i])
      break;

  size = handle->code << 4;
  size |= i + 1;
  bit_write_RC (dat, size);

  for (; i >= 0; i--)
    bit_write_RC (dat, val[i]);
}