Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: PATCH: load_map_data macro (PR#1012)
Home

[Freeciv-Dev] Re: PATCH: load_map_data macro (PR#1012)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: PATCH: load_map_data macro (PR#1012)
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Oct 2001 10:43:27 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Mon, Oct 15, 2001 at 01:30:44AM -0700, jdorje@xxxxxxxxxxxxxxxxxxxxx wrote:
> Raimar Falke wrote:
> > 
> > On Mon, Oct 15, 2001 at 03:10:17AM -0400, Jason Dorje Short wrote:
> > > Raimar Falke wrote:
> 
> > > > dec2hex is wrong. It isn't the converting between two number systems
> > > > but rather a binary2ascii_hex. One side of the convertion is a
> > > > hex string/char and the other is a number in the internal
> > > > representation of the computer. This internal number doesn't have a
> > > > number system. It isn't decimal.
> 
> > > - bin2ascii_hex, ascii_hex2bin
> > 
> > This one. And now somebody will shout: Raimar takes always the longer
> > method names ;)
> > 
> > > - bin2hex, hex2bin
> > > - bin2ascii, ascii2bin
> 
> The attached patch makes this change.

And another nitpick: ascii_hex2bin uses hex_chars and bin2ascii_hex
doesn't. Also I think that the function overhead of bin2ascii_hex and
ascii_hex2bin may be large. Have you profiled this?

> +static const char hex_chars[] = "0123456789abcdef";

> +/***************************************************************
> +This returns an ascii hex value of the given half-byte of the
> +binary integer.  See ascii_hex2bin().
> +  example: bin2ascii_hex(0xa00, 2) == 'a'
> +***************************************************************/
> +static char bin2ascii_hex(int value, int halfbyte_wanted)
> +{
> +  return hex_chars[(value >> (halfbyte_wanted * 4)) & 0xf];
> +}
> +
> +/***************************************************************
> +This returns a binary integer value of the ascii hex char,
> +offset by the given number of half-bytes.  See bin2ascii_hex().
> +  example: ascii_hex2bin('a', 2) == 0xa00
> +***************************************************************/
> +static int ascii_hex2bin(char ch, int offset)
> +{
> +  if (!isxdigit(ch)) {
> +    if (ch == ' ') {
> +      return 0; /* sane value */
> +    } else {
> +      freelog(LOG_FATAL, "unknown hex value ('%c')", ch);
> +      exit(1);
> +    }
> +  }
> +  return (ch-(isdigit(ch) ? '0' : 'a'-10)) << (offset * 4);
> +}

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Python 2.0 beta 1 is now available [...]. There is a long list of new 
  features since Python 1.6, released earlier today. We don't plan on 
  any new releases in the next 24 hours."
    -- Jeremy Hylton at Slashdot


[Prev in Thread] Current Thread [Next in Thread]