9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: hugo rivera <uair00@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] xd
Date: Wed, 20 May 2009 14:02:22 +0200	[thread overview]
Message-ID: <138575260905200502k3ebb0eb6o439426118e2083c0@mail.gmail.com> (raw)
In-Reply-To: <b1ab12b31895f468c702cbaaa3bb0ae9@quanstro.net>

Uh, thanks for the reply.
Now that I think about it endianness was the obvious reason behind this.
Saludos

2009/5/20, erik quanstrom <quanstro@quanstro.net>:
> On Wed May 20 06:57:14 EDT 2009, uair00@gmail.com wrote:
>  > I have an xd(1) question. Am I wrong or xd gets the byte ordering wrong?
>
>
> no.  xd is correct.  if you're running on an intel,
>  you're running on a little-endian machine which
>  means that numbers are stored in the reverse order
>  they are written.
>
>  #include <u.h>
>  #include <libc.h>
>
>  void
>  main(void)
>  {
>         uchar e[8] = {0, 1, 2, 3, 4, 5, 6, 7};
>         int i;
>         uvlong l;
>
>         l = *(uvlong*)e;
>         print("%.16llux\n", l);
>
>         l = 0x01020304050607ull;
>         memcpy(e, &l, 8);
>         for(i = 0; i < nelem(e); i++)
>                 print("%.2ux", e[i]);
>         print("\n");
>  }
>
>  see http://en.wikipedia.org/wiki/Endianness
>
>
>  > 2. xd output from p9p shows exactly the opposite byte ordering that
>  > hexdump output.
>  > Perhaps there's something wrong with xd.
>
>
> neither is wrong.  hexdump is just underspecified.  hexdump
>  doesn't say what the endianness of its output is.  xd on the other
>  hand does:
>
>           Formats other than -c are specified by pairs of characters
>           telling size and style, `4x' by default.  The sizes are
>
>           1 or b   1-byte units.
>           2 or w   2-byte big-endian units.
>           4 or l   4-byte big-endian units.
>           8 or v   8-byte big-endian units.
>
>  so numbers will be printed in reverse on an intel machine.
>  but the same network packet will be printed the same way
>  by xd on a big-endian sender and a little-endian recipient.
>
>
>  - erik
>
>


--
Hugo



      reply	other threads:[~2009-05-20 12:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-20 10:55 hugo rivera
2009-05-20 11:39 ` erik quanstrom
2009-05-20 12:02   ` hugo rivera [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=138575260905200502k3ebb0eb6o439426118e2083c0@mail.gmail.com \
    --to=uair00@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).