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: Wed, 17 Oct 2001 11:34:48 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Tue, Oct 16, 2001 at 11:20:44PM -0400, Jason Dorje Short wrote:
> Raimar Falke wrote:
> > 
> 
> > This still leaves the use-char-array-and-strchar-vs-if-or-?: issue.
> 
> Damn, I knew I was forgetting something.
> 
> This time I've dropped the hex_chars array and use simple (actually very
> simple) math to make the conversion.
> 
> I've also taken a save game (a fairly late-game one), loaded it, and
> saved the game anew both with and without the LOAD_MAP_DATA patch:
> 
> [jshort@jason freeciv]$ md5sum test*
> 06b97430ee938ca939854fd2d79b6ea9  test1
> 06b97430ee938ca939854fd2d79b6ea9  test2
> 06b97430ee938ca939854fd2d79b6ea9  test3
> 
> In other words, the result of a save-load-save remains the same under
> this patch.  Summary: the patch is probably correct.

> +/***************************************************************
> +This returns an ascii hex value of the given half-byte of the
> +binary integer.  See ascii_hex2bin().
> +  example: bin2ascii_hex(0xa00, 2) == 'a'
> +***************************************************************/
> +#define bin2ascii_hex(value, halfbyte_wanted)       \
> +  ('a' - 10 + (char)(((value) >> ((halfbyte_wanted) * 4)) & 0xf))
     ('a' - 10 + (char)(x))

0<=x<=15

For: x=0   ('a'-10+0) == 'W' WRONG
For: x=11  ('a'-10+11) = ('a'+1) == 'b' OK

IMHO there is no correct way without evaluating "value" more than one
or creating a local variable. So I would vote for the hex_chars
approach.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  The trick is to keep breathing.


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