Bit shifts and endianness

Discussion in 'C Programming' started by gamehack, Jan 5, 2006.

  1. gamehack

    slebetman Guest

    Hmm, I posted a reply on this issue but it seems it disappeared. Google
    bug?
    'Values' don't have number bases. Representations of the value do.
    No, you seem to be playing games with language confusing the value of a
    representation to the representation itself.
    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.
    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
    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).
    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).
     
    slebetman, Jan 8, 2006
    #41
    1. Advertisements

  2. gamehack

    slebetman Guest

    Hmm, I posted a reply on this issue but it seems it disappeared. Google
    bug?
    'Values' don't have number bases. Representations of the value do.
    No, you seem to be playing games with language confusing the value of a
    representation to the representation itself.
    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.
    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
    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).
    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).
     
    slebetman, Jan 8, 2006
    #42
    1. Advertisements

  3. gamehack

    slebetman Guest

    Hmm, I posted a reply on this issue but it seems it disappeared. Google
    bug?
    'Values' don't have number bases. Representations of the value do.
    No, you seem to be playing games with language confusing the value of a
    representation to the representation itself.
    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.
    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
    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).
    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).
     
    slebetman, Jan 8, 2006
    #43
  4. gamehack

    slebetman Guest

    Hmm, I posted a reply on this issue but it seems it disappeared. Google
    bug?
    'Values' don't have number bases. Representations of the value do.
    No, you seem to be playing games with language confusing the value of a
    representation to the representation itself.
    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.
    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
    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).
    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).
     
    slebetman, Jan 8, 2006
    #44
  5. gamehack

    slebetman Guest

    Hmm, I posted a reply on this issue but it seems it disappeared. Google
    bug?
    'Values' don't have number bases. Representations of the value do.
    No, you seem to be playing games with language confusing the value of a
    representation to the representation itself.
    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.
    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
    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).
    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).
     
    slebetman, Jan 8, 2006
    #45
  6. gamehack

    slebetman Guest

    Hmm, I posted a reply on this issue but it seems it disappeared. Google
    bug?
    'Values' don't have number bases. Representations of the value do.
    No, you seem to be playing games with language confusing the value of a
    representation to the representation itself.
    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.
    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
    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).
    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).
     
    slebetman, Jan 8, 2006
    #46
  7. gamehack

    slebetman Guest

    Hmm, I posted a reply on this issue but it seems it disappeared. Google
    bug?
    'Values' don't have number bases. Representations of the value do.
    No, you seem to be playing games with language confusing the value of a
    representation to the representation itself.
    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.
    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
    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).
    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).
     
    slebetman, Jan 8, 2006
    #47
  8. gamehack

    slebetman Guest

    Hmm, I posted a reply on this issue but it seems it disappeared. Google
    bug?
    'Values' don't have number bases. Representations of the value do.
    No, you seem to be playing games with language confusing the value of a
    representation to the representation itself.
    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.
    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
    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).
    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).
     
    slebetman, Jan 8, 2006
    #48
  9. gamehack

    Chuck F. Guest

    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/>
     
    Chuck F., Jan 8, 2006
    #49
  10. gamehack

    Eric Sosman Guest

    Seems appropriate for a discussion that's become
    increasingly about religion.
     
    Eric Sosman, Jan 8, 2006
    #50
  11. gamehack

    Jordan Abel Guest

    What could a mathematician possibly have to say about the nature of the
    values of C data types?
     
    Jordan Abel, Jan 8, 2006
    #51
  12. gamehack

    Jordan Abel Guest

    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".
     
    Jordan Abel, Jan 8, 2006
    #52
  13. gamehack

    Coos Haak Guest

    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.
     
    Coos Haak, Jan 8, 2006
    #53
  14. 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".
     
    Keith Thompson, Jan 8, 2006
    #54
  15. 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.
     
    Keith Thompson, Jan 8, 2006
    #55
  16. gamehack

    ozbear Guest

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

    Oz
     
    ozbear, Jan 8, 2006
    #56
  17. gamehack

    Joe Wright Guest

    You should check with Richard Heathfield for permission before you do
    that. 77 base 8 may not be a value, but a representation.
     
    Joe Wright, Jan 8, 2006
    #57
  18. 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
     
    Mark McIntyre, Jan 8, 2006
    #58
  19. And since when was C programming synonymous with mathematics?
    And I'm still sorry, but you *are*.

    Enough said, its pointless arguing.

    Mark McIntyre
     
    Mark McIntyre, Jan 8, 2006
    #59
  20. 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.
     
    Keith Thompson, Jan 9, 2006
    #60
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.