Bit shifts and endianness

S

slebetman

Hmm, I posted a reply on this issue but it seems it disappeared. Google
bug?
Because 'stored' values do have number bases.

'Values' don't have number bases. Representations of the value do.
You seem to be playing games with language.

No, you seem to be playing games with language confusing the value of a
representation to the representation itself.
Values in C stored in 'int x' have binary representation in memory.

Store in where? In a CPU register, then yes it most probably is binary.
In the graphics frame buffer it is a bunch of pixels related to the
font which when read by a human represents the value. In a file on disk
then it is probably an ASCII string representing the value.
Whether 42, 052 or 0x2A the int in memory looks something like 0..00101010
in binary.

Yes. And it looks something like 42 in decimal and 52 in octal and 2A
in hexadecimal. You used the word 'looks'. That should tell you that
you are only talking about representation, not the value itselt.

If you want to see how that value it looks like in the real world,
under the microscope, instead of binary then it will probably look like
this:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

of course you can't tell what the value is because all D flip-flop
cells look the same under the microscope. But if you were to attach
tiny LEDs to the outputs you'll see something like:

off, off, off .. on, off, on, off, on, off

But then again, that's merely a representation issue of the actual
voltages:

0V, 0V .. 5V, 0V, 5V, 0V, 5V, 0V

which, again, is merely a representation of the number 42
The value of 'x >> 1' will look like 0..00010101 which seems to be a binary
operation to me.

Well, we are talking about C here. And C doesn't define it as a binary
operation. C defines it as an arithmetic operation equivalent to
modulo2(x/2).
What am I missing?

Someone confused the word 'value' with 'representation' earlier in the
thread and is now arguing with Richard about it.

Go back to what you learned in high school. A number 'base' defines a
'number system' used to represent a 'number'. Numbers (hence values) by
themselves don't have bases. But we need a way to write down
(represent) numbers in order to talk about them. Hence we need a number
system to describe numbers. A 'base' simply defines how much larger a
digit to the 'left' is compared to the current digit in that number.
Altering the base of a number system does not alter the 'value' of that
number itself. It merely alters the number system: how the number is
represented (otherwise I will find myself with fewer fingers if I
suddenly decide to count them in hex and more fingers if I decide to
count them in octal).
 
S

slebetman

Hmm, I posted a reply on this issue but it seems it disappeared. Google
bug?
Because 'stored' values do have number bases.

'Values' don't have number bases. Representations of the value do.
You seem to be playing games with language.

No, you seem to be playing games with language confusing the value of a
representation to the representation itself.
Values in C stored in 'int x' have binary representation in memory.

Store in where? In a CPU register, then yes it most probably is binary.
In the graphics frame buffer it is a bunch of pixels related to the
font which when read by a human represents the value. In a file on disk
then it is probably an ASCII string representing the value.
Whether 42, 052 or 0x2A the int in memory looks something like 0..00101010
in binary.

Yes. And it looks something like 42 in decimal and 52 in octal and 2A
in hexadecimal. You used the word 'looks'. That should tell you that
you are only talking about representation, not the value itselt.

If you want to see how that value it looks like in the real world,
under the microscope, instead of binary then it will probably look like
this:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

of course you can't tell what the value is because all D flip-flop
cells look the same under the microscope. But if you were to attach
tiny LEDs to the outputs you'll see something like:

off, off, off .. on, off, on, off, on, off

But then again, that's merely a representation issue of the actual
voltages:

0V, 0V .. 5V, 0V, 5V, 0V, 5V, 0V

which, again, is merely a representation of the number 42
The value of 'x >> 1' will look like 0..00010101 which seems to be a binary
operation to me.

Well, we are talking about C here. And C doesn't define it as a binary
operation. C defines it as an arithmetic operation equivalent to
modulo2(x/2).
What am I missing?

Someone confused the word 'value' with 'representation' earlier in the
thread and is now arguing with Richard about it.

Go back to what you learned in high school. A number 'base' defines a
'number system' used to represent a 'number'. Numbers (hence values) by
themselves don't have bases. But we need a way to write down
(represent) numbers in order to talk about them. Hence we need a number
system to describe numbers. A 'base' simply defines how much larger a
digit to the 'left' is compared to the current digit in that number.
Altering the base of a number system does not alter the 'value' of that
number itself. It merely alters the number system: how the number is
represented (otherwise I will find myself with fewer fingers if I
suddenly decide to count them in hex and more fingers if I decide to
count them in octal).
 
S

slebetman

Hmm, I posted a reply on this issue but it seems it disappeared. Google
bug?
Because 'stored' values do have number bases.

'Values' don't have number bases. Representations of the value do.
You seem to be playing games with language.

No, you seem to be playing games with language confusing the value of a
representation to the representation itself.
Values in C stored in 'int x' have binary representation in memory.

Store in where? In a CPU register, then yes it most probably is binary.
In the graphics frame buffer it is a bunch of pixels related to the
font which when read by a human represents the value. In a file on disk
then it is probably an ASCII string representing the value.
Whether 42, 052 or 0x2A the int in memory looks something like 0..00101010
in binary.

Yes. And it looks something like 42 in decimal and 52 in octal and 2A
in hexadecimal. You used the word 'looks'. That should tell you that
you are only talking about representation, not the value itselt.

If you want to see how that value it looks like in the real world,
under the microscope, instead of binary then it will probably look like
this:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

of course you can't tell what the value is because all D flip-flop
cells look the same under the microscope. But if you were to attach
tiny LEDs to the outputs you'll see something like:

off, off, off .. on, off, on, off, on, off

But then again, that's merely a representation issue of the actual
voltages:

0V, 0V .. 5V, 0V, 5V, 0V, 5V, 0V

which, again, is merely a representation of the number 42
The value of 'x >> 1' will look like 0..00010101 which seems to be a binary
operation to me.

Well, we are talking about C here. And C doesn't define it as a binary
operation. C defines it as an arithmetic operation equivalent to
modulo2(x/2).
What am I missing?

Someone confused the word 'value' with 'representation' earlier in the
thread and is now arguing with Richard about it.

Go back to what you learned in high school. A number 'base' defines a
'number system' used to represent a 'number'. Numbers (hence values) by
themselves don't have bases. But we need a way to write down
(represent) numbers in order to talk about them. Hence we need a number
system to describe numbers. A 'base' simply defines how much larger a
digit to the 'left' is compared to the current digit in that number.
Altering the base of a number system does not alter the 'value' of that
number itself. It merely alters the number system: how the number is
represented (otherwise I will find myself with fewer fingers if I
suddenly decide to count them in hex and more fingers if I decide to
count them in octal).
 
S

slebetman

Hmm, I posted a reply on this issue but it seems it disappeared. Google
bug?
Because 'stored' values do have number bases.

'Values' don't have number bases. Representations of the value do.
You seem to be playing games with language.

No, you seem to be playing games with language confusing the value of a
representation to the representation itself.
Values in C stored in 'int x' have binary representation in memory.

Store in where? In a CPU register, then yes it most probably is binary.
In the graphics frame buffer it is a bunch of pixels related to the
font which when read by a human represents the value. In a file on disk
then it is probably an ASCII string representing the value.
Whether 42, 052 or 0x2A the int in memory looks something like 0..00101010
in binary.

Yes. And it looks something like 42 in decimal and 52 in octal and 2A
in hexadecimal. You used the word 'looks'. That should tell you that
you are only talking about representation, not the value itselt.

If you want to see how that value it looks like in the real world,
under the microscope, instead of binary then it will probably look like
this:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

of course you can't tell what the value is because all D flip-flop
cells look the same under the microscope. But if you were to attach
tiny LEDs to the outputs you'll see something like:

off, off, off .. on, off, on, off, on, off

But then again, that's merely a representation issue of the actual
voltages:

0V, 0V .. 5V, 0V, 5V, 0V, 5V, 0V

which, again, is merely a representation of the number 42
The value of 'x >> 1' will look like 0..00010101 which seems to be a binary
operation to me.

Well, we are talking about C here. And C doesn't define it as a binary
operation. C defines it as an arithmetic operation equivalent to
modulo2(x/2).
What am I missing?

Someone confused the word 'value' with 'representation' earlier in the
thread and is now arguing with Richard about it.

Go back to what you learned in high school. A number 'base' defines a
'number system' used to represent a 'number'. Numbers (hence values) by
themselves don't have bases. But we need a way to write down
(represent) numbers in order to talk about them. Hence we need a number
system to describe numbers. A 'base' simply defines how much larger a
digit to the 'left' is compared to the current digit in that number.
Altering the base of a number system does not alter the 'value' of that
number itself. It merely alters the number system: how the number is
represented (otherwise I will find myself with fewer fingers if I
suddenly decide to count them in hex and more fingers if I decide to
count them in octal).
 
S

slebetman

Hmm, I posted a reply on this issue but it seems it disappeared. Google
bug?
Because 'stored' values do have number bases.

'Values' don't have number bases. Representations of the value do.
You seem to be playing games with language.

No, you seem to be playing games with language confusing the value of a
representation to the representation itself.
Values in C stored in 'int x' have binary representation in memory.

Store in where? In a CPU register, then yes it most probably is binary.
In the graphics frame buffer it is a bunch of pixels related to the
font which when read by a human represents the value. In a file on disk
then it is probably an ASCII string representing the value.
Whether 42, 052 or 0x2A the int in memory looks something like 0..00101010
in binary.

Yes. And it looks something like 42 in decimal and 52 in octal and 2A
in hexadecimal. You used the word 'looks'. That should tell you that
you are only talking about representation, not the value itselt.

If you want to see how that value it looks like in the real world,
under the microscope, instead of binary then it will probably look like
this:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

of course you can't tell what the value is because all D flip-flop
cells look the same under the microscope. But if you were to attach
tiny LEDs to the outputs you'll see something like:

off, off, off .. on, off, on, off, on, off

But then again, that's merely a representation issue of the actual
voltages:

0V, 0V .. 5V, 0V, 5V, 0V, 5V, 0V

which, again, is merely a representation of the number 42
The value of 'x >> 1' will look like 0..00010101 which seems to be a binary
operation to me.

Well, we are talking about C here. And C doesn't define it as a binary
operation. C defines it as an arithmetic operation equivalent to
modulo2(x/2).
What am I missing?

Someone confused the word 'value' with 'representation' earlier in the
thread and is now arguing with Richard about it.

Go back to what you learned in high school. A number 'base' defines a
'number system' used to represent a 'number'. Numbers (hence values) by
themselves don't have bases. But we need a way to write down
(represent) numbers in order to talk about them. Hence we need a number
system to describe numbers. A 'base' simply defines how much larger a
digit to the 'left' is compared to the current digit in that number.
Altering the base of a number system does not alter the 'value' of that
number itself. It merely alters the number system: how the number is
represented (otherwise I will find myself with fewer fingers if I
suddenly decide to count them in hex and more fingers if I decide to
count them in octal).
 
S

slebetman

Hmm, I posted a reply on this issue but it seems it disappeared. Google
bug?
Because 'stored' values do have number bases.

'Values' don't have number bases. Representations of the value do.
You seem to be playing games with language.

No, you seem to be playing games with language confusing the value of a
representation to the representation itself.
Values in C stored in 'int x' have binary representation in memory.

Store in where? In a CPU register, then yes it most probably is binary.
In the graphics frame buffer it is a bunch of pixels related to the
font which when read by a human represents the value. In a file on disk
then it is probably an ASCII string representing the value.
Whether 42, 052 or 0x2A the int in memory looks something like 0..00101010
in binary.

Yes. And it looks something like 42 in decimal and 52 in octal and 2A
in hexadecimal. You used the word 'looks'. That should tell you that
you are only talking about representation, not the value itselt.

If you want to see how that value it looks like in the real world,
under the microscope, instead of binary then it will probably look like
this:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

of course you can't tell what the value is because all D flip-flop
cells look the same under the microscope. But if you were to attach
tiny LEDs to the outputs you'll see something like:

off, off, off .. on, off, on, off, on, off

But then again, that's merely a representation issue of the actual
voltages:

0V, 0V .. 5V, 0V, 5V, 0V, 5V, 0V

which, again, is merely a representation of the number 42
The value of 'x >> 1' will look like 0..00010101 which seems to be a binary
operation to me.

Well, we are talking about C here. And C doesn't define it as a binary
operation. C defines it as an arithmetic operation equivalent to
modulo2(x/2).
What am I missing?

Someone confused the word 'value' with 'representation' earlier in the
thread and is now arguing with Richard about it.

Go back to what you learned in high school. A number 'base' defines a
'number system' used to represent a 'number'. Numbers (hence values) by
themselves don't have bases. But we need a way to write down
(represent) numbers in order to talk about them. Hence we need a number
system to describe numbers. A 'base' simply defines how much larger a
digit to the 'left' is compared to the current digit in that number.
Altering the base of a number system does not alter the 'value' of that
number itself. It merely alters the number system: how the number is
represented (otherwise I will find myself with fewer fingers if I
suddenly decide to count them in hex and more fingers if I decide to
count them in octal).
 
S

slebetman

Hmm, I posted a reply on this issue but it seems it disappeared. Google
bug?
Because 'stored' values do have number bases.

'Values' don't have number bases. Representations of the value do.
You seem to be playing games with language.

No, you seem to be playing games with language confusing the value of a
representation to the representation itself.
Values in C stored in 'int x' have binary representation in memory.

Store in where? In a CPU register, then yes it most probably is binary.
In the graphics frame buffer it is a bunch of pixels related to the
font which when read by a human represents the value. In a file on disk
then it is probably an ASCII string representing the value.
Whether 42, 052 or 0x2A the int in memory looks something like 0..00101010
in binary.

Yes. And it looks something like 42 in decimal and 52 in octal and 2A
in hexadecimal. You used the word 'looks'. That should tell you that
you are only talking about representation, not the value itselt.

If you want to see how that value it looks like in the real world,
under the microscope, instead of binary then it will probably look like
this:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

of course you can't tell what the value is because all D flip-flop
cells look the same under the microscope. But if you were to attach
tiny LEDs to the outputs you'll see something like:

off, off, off .. on, off, on, off, on, off

But then again, that's merely a representation issue of the actual
voltages:

0V, 0V .. 5V, 0V, 5V, 0V, 5V, 0V

which, again, is merely a representation of the number 42
The value of 'x >> 1' will look like 0..00010101 which seems to be a binary
operation to me.

Well, we are talking about C here. And C doesn't define it as a binary
operation. C defines it as an arithmetic operation equivalent to
modulo2(x/2).
What am I missing?

Someone confused the word 'value' with 'representation' earlier in the
thread and is now arguing with Richard about it.

Go back to what you learned in high school. A number 'base' defines a
'number system' used to represent a 'number'. Numbers (hence values) by
themselves don't have bases. But we need a way to write down
(represent) numbers in order to talk about them. Hence we need a number
system to describe numbers. A 'base' simply defines how much larger a
digit to the 'left' is compared to the current digit in that number.
Altering the base of a number system does not alter the 'value' of that
number itself. It merely alters the number system: how the number is
represented (otherwise I will find myself with fewer fingers if I
suddenly decide to count them in hex and more fingers if I decide to
count them in octal).
 
S

slebetman

Hmm, I posted a reply on this issue but it seems it disappeared. Google
bug?
Because 'stored' values do have number bases.

'Values' don't have number bases. Representations of the value do.
You seem to be playing games with language.

No, you seem to be playing games with language confusing the value of a
representation to the representation itself.
Values in C stored in 'int x' have binary representation in memory.

Store in where? In a CPU register, then yes it most probably is binary.
In the graphics frame buffer it is a bunch of pixels related to the
font which when read by a human represents the value. In a file on disk
then it is probably an ASCII string representing the value.
Whether 42, 052 or 0x2A the int in memory looks something like 0..00101010
in binary.

Yes. And it looks something like 42 in decimal and 52 in octal and 2A
in hexadecimal. You used the word 'looks'. That should tell you that
you are only talking about representation, not the value itselt.

If you want to see how that value it looks like in the real world,
under the microscope, instead of binary then it will probably look like
this:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

of course you can't tell what the value is because all D flip-flop
cells look the same under the microscope. But if you were to attach
tiny LEDs to the outputs you'll see something like:

off, off, off .. on, off, on, off, on, off

But then again, that's merely a representation issue of the actual
voltages:

0V, 0V .. 5V, 0V, 5V, 0V, 5V, 0V

which, again, is merely a representation of the number 42
The value of 'x >> 1' will look like 0..00010101 which seems to be a binary
operation to me.

Well, we are talking about C here. And C doesn't define it as a binary
operation. C defines it as an arithmetic operation equivalent to
modulo2(x/2).
What am I missing?

Someone confused the word 'value' with 'representation' earlier in the
thread and is now arguing with Richard about it.

Go back to what you learned in high school. A number 'base' defines a
'number system' used to represent a 'number'. Numbers (hence values) by
themselves don't have bases. But we need a way to write down
(represent) numbers in order to talk about them. Hence we need a number
system to describe numbers. A 'base' simply defines how much larger a
digit to the 'left' is compared to the current digit in that number.
Altering the base of a number system does not alter the 'value' of that
number itself. It merely alters the number system: how the number is
represented (otherwise I will find myself with fewer fingers if I
suddenly decide to count them in hex and more fingers if I decide to
count them in octal).
 
C

Chuck F.

Gordon said:
Representations have bases. Values do not.


If I add 5 in base two to 3 in base five, what base is the
result in? Why? If your answer is "any base you want it to be
in", this really suggests that the base is separate from the
value.

Oh, yes, what base is the *BASE* in?

It's time to start talking about 1 to 1 correspondence with the set
of cardinals. :)

--
"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/>
 
E

Eric Sosman

Chuck said:
[...]
It's time to start talking about 1 to 1 correspondence with the set of
cardinals. :)

Seems appropriate for a discussion that's become
increasingly about religion.
 
J

Jordan Abel

Mark McIntyre said:


Well, Mark, I must disagree, and I think you'll find any mathematician
worth his salt disagreeing with you too. Values are indeed independent
of number base, whether you see meaning in that statement or not.

What could a mathematician possibly have to say about the nature of the
values of C data types?
 
J

Jordan Abel

Representations have bases. Values do not.


If I add 5 in base two to 3 in base five, what base is the result
in? Why? If your answer is "any base you want it to be in", this
really suggests that the base is separate from the value.

Clearly you can only add numbers in the same base - so the result is in
whichever base you converted one or the other (or both) to.

Since an int is made up of "value bits", "padding bits", and a "sign
bit", clearly it has a binary value. There is no provision for a "sign
decimal digit" or a "padding hex digit".
 
C

Coos Haak

Op 8 Jan 2006 19:02:18 GMT schreef Jordan Abel:
Since an int is made up of "value bits", "padding bits", and a "sign
bit", clearly it has a binary value. There is no provision for a "sign
decimal digit" or a "padding hex digit".

Even Leibniz would have understood the word "bit" as meaning "a part of"
It has nothing to do here with binary.

My native dialect knows the same meaning.
 
K

Keith Thompson

Coos Haak said:
Op 8 Jan 2006 19:02:18 GMT schreef Jordan Abel:


Even Leibniz would have understood the word "bit" as meaning "a part of"
It has nothing to do here with binary.

My native dialect knows the same meaning.

Leibniz wasn't a computer scientist.

Yes the English word "bit" means, among other things, "a small piece
or quantity of some material thing", but the word used in the C
standard (which has the same spelling and pronunciation, but is a
different word) is a contraction of "binary digit".

The C standard defines a "bit" as a "unit of data storage in the
execution environment large enough to hold an object that may have one
of two values".
 
K

Keith Thompson

Keith Thompson said:
Leibniz wasn't a computer scientist.

I probably should have said that Leibniz wasn't a *modern* computer
scientist. (He invented, but didn't publish, a form of symbolic logic
about 180 years before George Boole). The term "bit" meaning "binary
digit" only goes back to 1948.
 
O

ozbear

Clearly you can only add numbers in the same base - so the result is in
whichever base you converted one or the other (or both) to.

I can add 1, base 36, to 77, base 8 quite easily.

Oz
 
J

Joe Wright

ozbear said:
I can add 1, base 36, to 77, base 8 quite easily.

Oz

You should check with Richard Heathfield for permission before you do
that. 77 base 8 may not be a value, but a representation.
 
M

Mark McIntyre

Well, Mark, I must disagree, and I think you'll find any mathematician worth
his salt disagreeing with you too. Values are indeed independent of number
base, whether you see meaning in that statement or not.

Oh sure, but I need hardly remind you we're not in
comp.lang.mathematica or alt.maths. Computer programmes operate on
physically stored data.
Mark McIntyre
 
M

Mark McIntyre

Mark McIntyre said:


You can call it that if you want. But I call it mathematics.

And since when was C programming synonymous with mathematics?
No, we really really are not.

And I'm still sorry, but you *are*.

Enough said, its pointless arguing.

Mark McIntyre
 
K

Keith Thompson

Mark McIntyre said:
And since when was C programming synonymous with mathematics?
And I'm still sorry, but you *are*.
Enough said, its pointless arguing.

Ok, I'll chime in and describe how I tend think of it. I'm not sure
whether the standard agrees with me, but I think it's at least a
consistent model of what happens in the abstract machine.

An object has a representation. Objects are made of bits; the
representation is a logical mapping from the value to a sequence of
bits.

A value is an abstract entity that logically doesn't have a
representation. It's probably going to be stored somehow (in a
register, as transient signals on wires, or whatever), but since there
isn't necessarily an object in which the value is stored, it's
meaningless (from the point of view of the abstract machine) to talk
about the representation of a value. A representation is created only
when a value is stored in an object.

For example, given

int x = 10;
int y = 20;
int z = x + y;

the object x will have contain the binary representation ....1010, and
y will contain the binary representation ....10100, but the
representation ...11100 doesn't exist *in the abstract machine* during
the evaluation of x + y; a representation exists only when the value
is stored in an object.

I think the wording of C99 6.2.6 "Representations of types" tends to
support this model, or at least is consistent with it. For example,
it talks about "[v]alues stored in non-bit-field objects"; it doesn't
talk about values not stored in objects.

As far as the standard is concerned, objects have to be composed of
bits, but values not stored in objects, though they may have
representations of some sort in hardware, have no meaningful
representations as far as the standard is concerned. The standard's
requirement for a binary representation for unsigned integer *objects*
doesn't preclude a trinary or decimal representation for unsigned
integer *values* (e.g., intermediate expression results that exist
only in the CPU and are never stored to memory).

I'd be interested in seeing something in the standard that's
inconsistent with this model.
 

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,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top