Bit twiddling

C

CBFalconer

Joe said:
Chris Croughton wrote:
.... snip ...

In the end, happily, it doesn't matter. It's just a matter of
notation. It doesn't change the way the machine works, only how
it's described in the docs.

The way that makes some sense, and is normally not implemented, is
to have the numbering a continuation of the storage address
scheme. If a lower address is a less significant byte, then a
lower bit number should be a less significant bit. That way bit
addresses can be a simple concatenation of entities.
More interesting is a bit's value in time. Think of async serial
bytes: start bit, 8 data bits and stop bit. It is of crucial
importance that we know whether the bit after the start bit is the
lsb or the msb of the byte. I used to know. Really. :)

So did I once upon a time. Luckily it is one or t'other.
 
P

Paul Mesken

On Sat, 04 Jun 2005 14:39:08 +0200, Paul Mesken


It certainly does, but early specs tended to look at it from a graphical
point of view:

+---+---+---+---+---+---+---+---+
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
+---+---+---+---+---+---+---+---+

and it probably seemed more logical to number left to right.

Well, for those reading from left to right it does, I guess :)

It's a bit like showing a graph of memory. Some have the highest
address at the top, others the lowest address.
An alternative explanation is that they were French <g>...

It's all because of the metric system ;-)
(Naughty Chris! Mustn't mock the French, they voted the right way on
the EU constitution. Perhaps one day they'll even forgive us for
Agincourt...)

It wasn't bad (55% 'Non') but us Dutch topped it with 62% 'Nee'.
Perhaps you will now forgive us for the "Chatham Raid" :)
 
R

Richard Harter

It certainly does, but early specs tended to look at it from a graphical
point of view:

+---+---+---+---+---+---+---+---+
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
+---+---+---+---+---+---+---+---+

and it probably seemed more logical to number left to right.

One reason for using msb is that it preserves lexicographic order;
comparisons are performed on the msb down to the lsb. Frex the string
"I am a string" is stored (using msb) as

0123 0123 0123 0123
I am a s trin g

and (using lsb) as

3210 3210 3210 3210
ma I s a nirt g




Richard Harter, (e-mail address removed)
http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.
 
C

Coos Haak

Op Sat, 04 Jun 2005 15:20:21 GMT schreef Richard Harter:

[snip]
One reason for using msb is that it preserves lexicographic order;
comparisons are performed on the msb down to the lsb. Frex the string
"I am a string" is stored (using msb) as

0123 0123 0123 0123
I am a s trin g

and (using lsb) as

3210 3210 3210 3210
ma I s a nirt g
You are confusing most/least significant bit with byte.
What you describe is called big/little endian.
 
C

CBFalconer

Chris said:
.... snip ...

(Naughty Chris! Mustn't mock the French, they voted the right
way on the EU constitution. Perhaps one day they'll even forgive
us for Agincourt...)

And Crecy, Waterloo, Trafalgar, Saintes. All known to us because
of our upbringing. I wonder if there are equivalents with the
opposite result (postdating Hastings), known to those brought up in
France.
 
C

Chris Croughton

In the end, happily, it doesn't matter. It's just a matter of notation.
It doesn't change the way the machine works, only how it's described in
the docs.

Which can mean a lot of time wasted getting protocols wrong. I was
lucky, when I started doing TCP/IP the communications were already out
there so I only had to do some 'sniffing' of them to confirm that the
spec. had the bits the other way round, but if it isn't defined properly
that sort of thing can cause a lot of wasted time and effort.
More interesting is a bit's value in time. Think of async serial bytes:
start bit, 8 data bits and stop bit. It is of crucial importance that we
know whether the bit after the start bit is the lsb or the msb of the
byte. I used to know. Really. :)

LSB first (see CCITT V.24) <g>. That one I /do/ remember, I was
programming async serial comms for a long time...

Chris C
 
C

Chris Croughton

Well, for those reading from left to right it does, I guess :)

Yup. I remember quite a few CS people boggling at numbering from high
to low (left to right).
It's a bit like showing a graph of memory. Some have the highest
address at the top, others the lowest address.

And there's no correlation I've found between that and big/little-endian
preference.
It's all because of the metric system ;-)

Which was Napoleon's fault said:
It wasn't bad (55% 'Non') but us Dutch topped it with 62% 'Nee'.
Perhaps you will now forgive us for the "Chatham Raid" :)

I don't think most Brits even know about the Chatham Raid. I suspect
that I only heard about it becasuse it was 'local' history when I was
growing up. Google has only a few hits, two of which are about
recovering data from RAID systems in Kent <g>...

Chris C
 
C

Chris Croughton

And Crecy, Waterloo, Trafalgar, Saintes. All known to us because
of our upbringing. I wonder if there are equivalents with the
opposite result (postdating Hastings), known to those brought up in
France.

I gather not many. I knew a person who had a job as tour guide in
Canterbury cathedral, and he said it was really embarassing -- not that
we'd fought virtually every country in Europe (they'd mostly fought each
other as well) but that we'd won pretty constistently since 1066! It
wouldn't have been as embarassing if we'd lost a few major ones...

Chris C
 
M

Michael Mair

Chris said:
I gather not many. I knew a person who had a job as tour guide in
Canterbury cathedral, and he said it was really embarassing -- not that
we'd fought virtually every country in Europe (they'd mostly fought each
other as well) but that we'd won pretty constistently since 1066! It
wouldn't have been as embarassing if we'd lost a few major ones...

You seem blissfully ignorant of the Hundred Years War -- losing France
to the French... ;-P

BTW: I am not sure whether it was really the right thing to vote against
the EU constitution. As I was not given the opportunity to decide, I did
not have a look at the 400 pages...

Cheers
Michael
 
P

Paul Mesken

I don't think most Brits even know about the Chatham Raid. I suspect
that I only heard about it becasuse it was 'local' history when I was
growing up. Google has only a few hits, two of which are about
recovering data from RAID systems in Kent <g>...

Ah, such a big difference with the Dutch. We all know about the
"battle of Medway". It was one of our finest moments, we innihilated
the British fleet and stole their flagship Royal Charles (which was
later sold for scrapping :)

Google will give some more hits with "Chatham", "Ruyter" and "Medway".
 
R

Richard Harter

Op Sat, 04 Jun 2005 15:20:21 GMT schreef Richard Harter:

[snip]
One reason for using msb is that it preserves lexicographic order;
comparisons are performed on the msb down to the lsb. Frex the string
"I am a string" is stored (using msb) as

0123 0123 0123 0123
I am a s trin g

and (using lsb) as

3210 3210 3210 3210
ma I s a nirt g
You are confusing most/least significant bit with byte.
What you describe is called big/little endian.

Er,no, I'm not. Big/little endian is a symptom.



Richard Harter, (e-mail address removed)
http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.
 
C

Coos Haak

Op Sun, 05 Jun 2005 16:23:43 GMT schreef Richard Harter:
Er,no, I'm not. Big/little endian is a symptom.
I still disagree, switching byte order makes a dump hard to read.
Swiching bit order make communication impossible.
 
J

Joe Wright

Coos said:
Op Sun, 05 Jun 2005 16:23:43 GMT schreef Richard Harter:



I still disagree, switching byte order makes a dump hard to read.
Swiching bit order make communication impossible.

Sorry Coos, you don't seem to get it yet. Bit order has nothing to do
with it. And byte order within int doesn't either.

char strng[] = "I am a string.";

will be represented exactly the same way in memory on big (Sun) and
little (Intel) endian machines. They are characters and endianness
doesn't come into play.

Switching bit order is a straw dog. You can only do it at the circuit
board level. Even then, nobody can tell whether you did or not.
 
C

Coos Haak

Op Sun, 05 Jun 2005 15:04:18 -0400 schreef Joe Wright:
Coos said:
Op Sun, 05 Jun 2005 16:23:43 GMT schreef Richard Harter:



I still disagree, switching byte order makes a dump hard to read.
Swiching bit order make communication impossible.

Sorry Coos, you don't seem to get it yet. Bit order has nothing to do
with it. And byte order within int doesn't either.

char strng[] = "I am a string.";

will be represented exactly the same way in memory on big (Sun) and
little (Intel) endian machines. They are characters and endianness
doesn't come into play.

Switching bit order is a straw dog. You can only do it at the circuit
board level. Even then, nobody can tell whether you did or not.

Is my English so dense? This is just what I wanted to say. These two
numberings have almost nothing in common.
OK. I'll sit down and drink quietly my evening coffee ;-)
 
C

CBFalconer

Chris said:
I gather not many. I knew a person who had a job as tour guide in
Canterbury cathedral, and he said it was really embarassing -- not
we'd fought virtually every country in Europe (they'd mostly fought
each other as well) but that we'd won pretty constistently since
1066! It wouldn't have been as embarassing if we'd lost a few
major ones...

The Dutch seem to have done better. I had always known of de
Ruyter, and somebody just brought up Medway and Chatham, which I
know nothing about. Of course the Anglo-Saxon-Normans have had the
great advantage of picking their fights with care, and not needing
to worry too much about ambitious sun-kings or emperors wanting to
annex them. That strip of water made a monstrous difference.
 
R

Richard Bos

Paul Mesken said:
Ah, such a big difference with the Dutch. We all know about the
"battle of Medway". It was one of our finest moments, we innihilated
the British fleet and stole their flagship Royal Charles (which was
later sold for scrapping :)

Not entirely. When the Rijksmuseum is reopened, I advise any Dutchman or
Englishman to take a look in its historical department:
<http://www.rijksmuseum.nl/aria/aria_assets/NG-MC-239?lang=en>

Richard
 
R

Richard Bos

Chris Croughton said:
I gather not many. I knew a person who had a job as tour guide in
Canterbury cathedral, and he said it was really embarassing -- not that
we'd fought virtually every country in Europe (they'd mostly fought each
other as well) but that we'd won pretty constistently since 1066! It
wouldn't have been as embarassing if we'd lost a few major ones...

I don't know which is more embarrasing: for the French, that they needed
a teenaged girl to kick you out of their country; for the English, that
it worked; or that all the world except you remembers Jeanne d'Arc...

Richard
 
C

CBFalconer

Richard said:
I don't know which is more embarrasing: for the French, that they
needed a teenaged girl to kick you out of their country; for the
English, that it worked; or that all the world except you remembers
Jeanne d'Arc...

Not so, the 'remembers'. At least not in Canada and the US. The
pyromaniacs are not remembered with favor either.
 
G

glen herrmannsfeldt

Chris Croughton wrote:

(snip)
(I wrote)
That's a good reason for numbering with 0 as LSB!

(snip)

Well, MSB bit 0 is more consistent with big endian byte order.

Some people don't believe that there needs to be such consistency
on machines that can't address bytes, but I disagree.

-- glen
 
M

Mark McIntyre

I gather not many. I knew a person who had a job as tour guide in
Canterbury cathedral, and he said it was really embarassing -- not that
we'd fought virtually every country in Europe (they'd mostly fought each
other as well) but that we'd won pretty constistently since 1066! It
wouldn't have been as embarassing if we'd lost a few major ones...

I don't know which is more embarrasing: for the French, that they needed
a teenaged girl to kick you out of their country; for the English, that
it worked; or that all the world except you remembers Jeanne d'Arc...[/QUOTE]

Of course, at the time, both sides were actually French anyway....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top