Velocity Reviews > Bit shifts and endianness

Bit shifts and endianness

Eric Sosman
Guest
Posts: n/a

 01-06-2006
Richard Heathfield wrote:

> Eric Sosman said:
>
>
>>Jordan Abel wrote:
>>
>>>That doesn't mean it's not a "binary value" - which, if you were
>>>paying attention, is the claim you are attempting to refute.

>>
>> Thank you, Jordan, for drawing my attention to my
>>inattention. Tracing back the thread, though, I find
>>this remark from Mark McIntyre:
>>
>> > No, they operate on a value. Values don't have number bases.
>> > That's merely a representation issue.

>
>
> No, those are my words, not Mark's.

Woops! My apologies for the misattribution.

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)lid

Chuck F.
Guest
Posts: n/a

 01-06-2006
Eric Sosman wrote:
> Jordan Abel wrote:
>>
>> That doesn't mean it's not a "binary value" - which, if you
>> were paying attention, is the claim you are attempting to
>> refute.

>
> Thank you, Jordan, for drawing my attention to my inattention.
> Tracing back the thread, though, I find this remark from Mark
> McIntyre:
>
>> No, they operate on a value. Values don't have number bases.
>> That's merely a representation issue.

>
> .... to which you responded:
>
>> The standard mentions "bits" in too many places for me to
>> believe this.

>
> McIntyre says the shift operators work on values, not
> representations, and you say you don't believe him. That's what
> I'm trying to refute: I add my voice to the McIntyre (and
> Heathfield) chorus to say that you are mistaken.

You can pick out any bit from a value, regardless of the underlying
representation, by dividing by a suitable power of 2, and then
taking the result modulo 2. The latter is simply the Pascal
function odd(n).

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>

Jordan Abel
Guest
Posts: n/a

 01-06-2006
On 2006-01-06, Eric Sosman <(E-Mail Removed)> wrote:
> Jordan Abel wrote:
>>
>> That doesn't mean it's not a "binary value" - which, if you were
>> paying attention, is the claim you are attempting to refute.

>
> Thank you, Jordan, for drawing my attention to my
> inattention. Tracing back the thread, though, I find
> this remark from Mark McIntyre:
>
> > No, they operate on a value. Values don't have number bases.
> > That's merely a representation issue.

>
> ... to which you responded:
>
> > The standard mentions "bits" in too many places for me to
> > believe this.

>
> McIntyre says the shift operators work on values, not
> representations, and you say you don't believe him.

No. The statement i disbelieved was "Values don't have number bases".
The base of an integer value is 2. The base of a floating-point value is
FLT_RADIX (2 on my system, may be 10 on others for example).

> That's
> what I'm trying to refute: I add my voice to the McIntyre
> (and Heathfield) chorus to say that you are mistaken.
>
> But perhaps the "this" in your response referred to
> something else altogether?
>

Eric Sosman
Guest
Posts: n/a

 01-06-2006
Chuck F. wrote:

> Eric Sosman wrote:
>
>> Jordan Abel wrote:
>>
>>>
>>> That doesn't mean it's not a "binary value" - which, if you
>>> were paying attention, is the claim you are attempting to
>>> refute.

>>
>>
>> Thank you, Jordan, for drawing my attention to my inattention.
>> Tracing back the thread, though, I find this remark from Mark
>> McIntyre:
>>
>>> No, they operate on a value. Values don't have number bases. That's
>>> merely a representation issue.

>>
>>
>> .... to which you responded:
>>
>>> The standard mentions "bits" in too many places for me to believe this.

>>
>>
>> McIntyre says the shift operators work on values, not representations,
>> and you say you don't believe him. That's what
>> I'm trying to refute: I add my voice to the McIntyre (and
>> Heathfield) chorus to say that you are mistaken.

>
>
> You can pick out any bit from a value, regardless of the underlying
> representation, by dividing by a suitable power of 2, and then taking
> the result modulo 2. The latter is simply the Pascal function odd(n).

Right. And you can pick out a trit by dividing by a suitable
power of three and taking the result modulo 3. Or you can pick
out quits with fours, quints with fives, dits with tens, twits
with twelves, and so on. As Richard Heathfield says (misattributed
by me to Mark McIntyre), "values don't have number bases." No
matter how many fingers you have, pi is pi is pi.

--
Eric Sosman
(E-Mail Removed)lid

Richard Heathfield
Guest
Posts: n/a

 01-06-2006
Jordan Abel said:

> The statement i disbelieved was "Values don't have number bases".

Then your beef is with me.

> The base of an integer value is 2.

No, it's not, neither in mathematics nor in C.

int i = 42;

Here, the 42 represents an integer. The representation used is denary, also
known as decimal.

int j = 052;

Here, the 052 represents an integer. The representation used is octal.

int k = 0x2A;

Here, the 0x2A represents an integer. The representation used is
hexadecimal.

In each of these three cases, the value is the same: it's the number of
asterisks in the following collection:

*****
*******
*********
*********
*******
*****

We have seen the same integer value represented in three different bases,
none of which was binary, and in a non-positional representation as well.
Values *don't* have bases. Bases are what we use to /represent/ values.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Mark McIntyre
Guest
Posts: n/a

 01-06-2006
On 6 Jan 2006 00:21:20 GMT, in comp.lang.c , Jordan Abel
<(E-Mail Removed)> wrote:

>On 2006-01-05, Richard Heathfield <(E-Mail Removed)> wrote:
>> Mark McIntyre said:
>>
>>> On Thu, 05 Jan 2006 20:26:11 GMT, in comp.lang.c , Keith Thompson
>>> <(E-Mail Removed)> wrote:
>>>
>>>>No. Shift operators are defined on the *values* of their operands,
>>>>not on their representations.
>>>
>>> Clarification: I assume you mean that shift operators operate on a
>>> binary value,

>>
>> No, they operate on a value. Values don't have number bases. That's merely a
>> representation issue.

>
>The standard mentions "bits" in too many places for me to believe this.

For some reason RJH's original post didn't make it here. However, my
response would have been " Rubbish", which is rare for a response to
an RJH post.

One can I suppose argue that you break the number down into a sum of
powers of two. Er, guys, thats called a "representation".

Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Mark McIntyre
Guest
Posts: n/a

 01-06-2006
On Fri, 06 Jan 2006 01:35:31 GMT, in comp.lang.c , Keith Thompson
<(E-Mail Removed)> wrote:

>Something along the lines of:
>
> An integer value in the range 0..2**(n-1) can be uniquely defined
> as a sum of powers of two: ... + b3 * 2**3 + b2 * 2**2 + b1 * 2**1
> + b0 * 2**0. Each bn value is referred to as the nth _bit_ of the
> integer value.

This is a representation of the value.
Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Richard Heathfield
Guest
Posts: n/a

 01-07-2006
Mark McIntyre said:

> On 6 Jan 2006 00:21:20 GMT, in comp.lang.c , Jordan Abel
> <(E-Mail Removed)> wrote:
>
>>On 2006-01-05, Richard Heathfield <(E-Mail Removed)> wrote:
>>> Mark McIntyre said:
>>>
>>>> Clarification: I assume you mean that shift operators operate on a
>>>> binary value,
>>>
>>> No, they operate on a value. Values don't have number bases. That's
>>> merely a representation issue.

>>
>>The standard mentions "bits" in too many places for me to believe this.

>
> For some reason RJH's original post didn't make it here. However, my
> response would have been " Rubbish", which is rare for a response to
> an RJH post.

That fact alone should give you pause for thought. What makes you think my
statement is rubbish?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

mensanator@aol.com
Guest
Posts: n/a

 01-07-2006

Mark McIntyre wrote:
> On 6 Jan 2006 00:21:20 GMT, in comp.lang.c , Jordan Abel
> <(E-Mail Removed)> wrote:
>
> >On 2006-01-05, Richard Heathfield <(E-Mail Removed)> wrote:
> >> Mark McIntyre said:
> >>
> >>> On Thu, 05 Jan 2006 20:26:11 GMT, in comp.lang.c , Keith Thompson
> >>> <(E-Mail Removed)> wrote:
> >>>
> >>>>No. Shift operators are defined on the *values* of their operands,
> >>>>not on their representations.
> >>>
> >>> Clarification: I assume you mean that shift operators operate on a
> >>> binary value,
> >>
> >> No, they operate on a value. Values don't have number bases. That's merely a
> >> representation issue.

> >
> >The standard mentions "bits" in too many places for me to believe this.

>
> For some reason RJH's original post didn't make it here. However, my
> response would have been " Rubbish", which is rare for a response to
> an RJH post.
>
> One can I suppose argue that you break the number down into a sum of
> powers of two. Er, guys, thats called a "representation".

But you must pick a representation to create an "implementation",
right?

You could implement integer representations as strings of characters
"0" and "1" and have unlimited precision arithmetic. Am I correct in
assuming the standard would allow this as long as evrything behaves as
it should?

>
>
>
>
>
>
> Mark McIntyre
> --
>
> ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Gordon Burditt
Guest
Posts: n/a

 01-07-2006
>But you must pick a representation to create an "implementation",
>right?
>
>You could implement integer representations as strings of characters
>"0" and "1" and have unlimited precision arithmetic. Am I correct in
>assuming the standard would allow this as long as evrything behaves as
>it should?

But it *WON'T* behave as it should. int can't be a variable size.
Also, there are practical and economic problems with sizeof(int) = infinity.

You could choose a large but finite size (say, 1 gigabit integers),
and that could be made to work.

Gordon L. Burditt

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post geo C Programming 4 11-21-2009 03:43 PM fermineutron C Programming 6 11-06-2006 02:53 AM bob_jenkins@burtleburtle.net C Programming 7 05-20-2006 01:46 PM Ross A. Finlayson C Programming 19 03-10-2005 03:57 AM Reid Nichol Python 11 09-11-2004 09:08 AM

Advertisments