Octal vs. Hex war o' death

From: Ian S. Nelson (ian.nelson@echostar.com)
Date: Wed Nov 29 2000 - 18:27:04 EST


I'm sure this is a religious issue... but I'm going to suggest it
anyways because I spent a few minutes on it.

So I was hacking away trying to get my embedded box to run the correct
stuff after booting up and I ran into an octal speed bump. You see, all
throughout rd.c there are these hex constants, like there should be. In
fact most constants in the kernel are in the 2 friendliest number
formats known, hex and dec.

in rd.c there is an:
memset(buf, 0xe5, size);

a:
 printk("%c\b", rotator[rotate & 0x3]);

and a:
#define WSIZE 0x8000

and several others, all in hex.

Then I ran into this black sheep:
 if (buf[0] == 037 && ((buf[1] == 0213) || (buf[1] == 0236))) {

I vote that we make this consistent and fix it. So I've included a
handy patch to correct this "bug." My rationale is that a) most
constants are in hex or dec already, b) my editor doesn't sport an
octal mode but it has a really handy hex mode that let's me do things
like load up an initrd and check to see that the first 2 bytes are set
correctly, c) octals were invented for UNIX file permissions and not
programming, putting an extra "0" in there just doesn't make sense and
shouldn't change the meaning of the following digits, "0x" on the other
hand clearly denotes that you are not looking at a base 10 number. In
math they teach you that you can arbitrarily add zeros to the front of a
number and not change it's meaning, such as the military frequently does
with time ("0700 hours.." which translates to "7:00" and not "4:48")
and math goes together hand in hand with programming. lastly, d) octal
numbers just don't have a good feeling to them, it's like your stuck at
half-duplex or something..

Ian

diff -urP virgin-linux/drivers/block/rd.c linux/drivers/block/rd.c
--- virgin-linux/drivers/block/rd.c Fri Nov 17 17:46:55 2000
+++ linux/drivers/block/rd.c Wed Nov 29 15:45:33 2000
@@ -497,7 +497,7 @@
         /*
          * If it matches the gzip magic numbers, return -1
          */
- if (buf[0] == 037 && ((buf[1] == 0213) || (buf[1] == 0236))) {
+ if (buf[0] == 0x1f && ((buf[1] == 0x8b) || (buf[1] == 0x9e))) {
                 printk(KERN_NOTICE
                        "RAMDISK: Compressed image found at block %d\n",
                        start_block);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Nov 30 2000 - 21:00:23 EST