8 bit integer type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zacariaz@gmail.com

    8 bit integer type

    typedef char int(myint8);

    the above is realy what i wanna do, but ofcourse it cant be done this
    way. I have looked around for a 8 bit integer type, but no luck. the
    int8_t and simular still acts like chars.
    Yes i know it a stupid little thing, but im getting tired of writing
    int(my8bitvar); all the time, and if there is a type that doesnt act
    like a char, i wanna know.

    I have allso tryed defining my own type, but got lost when i had to
    implement all the operator (==, -=, +=, ++, --, etc.) and besides it
    seemed a really stupid way to go about it.

    So please i anyone holds an answer, let me hear it.

    Regards

  • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

    #2
    Re: 8 bit integer type

    On 2007-08-29 11:45, zacariaz@gmail. com wrote:
    typedef char int(myint8);
    >
    the above is realy what i wanna do, but ofcourse it cant be done this
    way. I have looked around for a 8 bit integer type, but no luck. the
    int8_t and simular still acts like chars.
    Yes i know it a stupid little thing, but im getting tired of writing
    int(my8bitvar); all the time, and if there is a type that doesnt act
    like a char, i wanna know.
    In what way does a char differ in behaviour from an int, except for the
    range of values it can hold?

    --
    Erik Wikström

    Comment

    • zacariaz@gmail.com

      #3
      Re: 8 bit integer type

      On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia. comwrote:
      On 2007-08-29 11:45, zacar...@gmail. com wrote:
      >
      typedef char int(myint8);
      >
      the above is realy what i wanna do, but ofcourse it cant be done this
      way. I have looked around for a 8 bit integer type, but no luck. the
      int8_t and simular still acts like chars.
      Yes i know it a stupid little thing, but im getting tired of writing
      int(my8bitvar); all the time, and if there is a type that doesnt act
      like a char, i wanna know.
      >
      In what way does a char differ in behaviour from an int, except for the
      range of values it can hold?
      >
      --
      Erik Wikström
      Of course it doesnt differ much, but it does differ, fx. what do you
      think happened when i first head about the stdint.h and wanted to try
      out the uint8-t?

      @code
      uint8_t var = 7;
      std::cout << var;
      @code

      BEEP! it said.
      Imagine my surprise. and integer type making funny noises?


      Yes, it is a tiny little wee wee thing that nobody care about, but
      still it enoys me having to write
      std::cout << int(var);
      Yes, it is only 5 extra letter, well that depends, but the goal of
      this post was only to make certain that a real 8 bit integer type or
      an easy soluton doesnt allready excist.

      Comment

      • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

        #4
        Re: 8 bit integer type

        On 2007-08-29 12:35, zacariaz@gmail. com wrote:
        On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia. comwrote:
        >On 2007-08-29 11:45, zacar...@gmail. com wrote:
        >>
        typedef char int(myint8);
        >>
        the above is realy what i wanna do, but ofcourse it cant be done this
        way. I have looked around for a 8 bit integer type, but no luck. the
        int8_t and simular still acts like chars.
        Yes i know it a stupid little thing, but im getting tired of writing
        int(my8bitvar); all the time, and if there is a type that doesnt act
        like a char, i wanna know.
        >>
        >In what way does a char differ in behaviour from an int, except for the
        >range of values it can hold?
        >>
        >--
        >Erik Wikström
        >
        Of course it doesnt differ much, but it does differ, fx. what do you
        think happened when i first head about the stdint.h and wanted to try
        out the uint8-t?
        >
        @code
        uint8_t var = 7;
        std::cout << var;
        @code
        >
        BEEP! it said.
        Imagine my surprise. and integer type making funny noises?
        >
        >
        Yes, it is a tiny little wee wee thing that nobody care about, but
        still it enoys me having to write
        std::cout << int(var);
        Yes, it is only 5 extra letter, well that depends, but the goal of
        this post was only to make certain that a real 8 bit integer type or
        an easy soluton doesnt allready excist.
        Yes, I see. This is of course because uint8_t is just a typedef of an
        unsigned char. I don't think anyone but the compiler vendor or library
        vendor can fix this.

        --
        Erik Wikström

        Comment

        • anon

          #5
          Re: 8 bit integer type

          zacariaz@gmail. com wrote:
          On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia. comwrote:
          >On 2007-08-29 11:45, zacar...@gmail. com wrote:
          >>
          >>typedef char int(myint8);
          >>the above is realy what i wanna do, but ofcourse it cant be done this
          >>way. I have looked around for a 8 bit integer type, but no luck. the
          >>int8_t and simular still acts like chars.
          >>Yes i know it a stupid little thing, but im getting tired of writing
          >>int(my8bitvar ); all the time, and if there is a type that doesnt act
          >>like a char, i wanna know.
          >In what way does a char differ in behaviour from an int, except for the
          >range of values it can hold?
          >>
          >--
          >Erik Wikström
          >
          Of course it doesnt differ much, but it does differ, fx. what do you
          think happened when i first head about the stdint.h and wanted to try
          out the uint8-t?
          >
          @code
          uint8_t var = 7;
          std::cout << var;
          @code
          >
          BEEP! it said.
          Imagine my surprise. and integer type making funny noises?
          >
          >
          Yes, it is a tiny little wee wee thing that nobody care about, but
          still it enoys me having to write
          std::cout << int(var);
          Yes, it is only 5 extra letter, well that depends, but the goal of
          this post was only to make certain that a real 8 bit integer type or
          an easy soluton doesnt allready excist.
          >
          struct int8bit
          {
          unsigned int number : 8;
          }

          then implement a class which does everything you want to do with this.

          Comment

          • zacariaz@gmail.com

            #6
            Re: 8 bit integer type

            On 29 Aug., 13:24, anon <a...@no.nowrot e:
            zacar...@gmail. com wrote:
            On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia. comwrote:
            On 2007-08-29 11:45, zacar...@gmail. com wrote:
            >
            >typedef char int(myint8);
            >the above is realy what i wanna do, but ofcourse it cant be done this
            >way. I have looked around for a 8 bit integer type, but no luck. the
            >int8_t and simular still acts like chars.
            >Yes i know it a stupid little thing, but im getting tired of writing
            >int(my8bitvar) ; all the time, and if there is a type that doesnt act
            >like a char, i wanna know.
            In what way does a char differ in behaviour from an int, except for the
            range of values it can hold?
            >
            --
            Erik Wikström
            >
            Of course it doesnt differ much, but it does differ, fx. what do you
            think happened when i first head about the stdint.h and wanted to try
            out the uint8-t?
            >
            @code
            uint8_t var = 7;
            std::cout << var;
            @code
            >
            BEEP! it said.
            Imagine my surprise. and integer type making funny noises?
            >
            Yes, it is a tiny little wee wee thing that nobody care about, but
            still it enoys me having to write
            std::cout << int(var);
            Yes, it is only 5 extra letter, well that depends, but the goal of
            this post was only to make certain that a real 8 bit integer type or
            an easy soluton doesnt allready excist.
            >
            struct int8bit
            {
            unsigned int number : 8;
            >
            }
            >
            then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -
            >
            - Vis tekst i anførselstegn -
            ah yes, two problems reamins however.
            1. How much space does this new type use in memory? i mean is it just
            an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?
            2. this vould not be used as a regular type but would have to be
            called like int8bit.number, this is not that important, but really it
            would be tha same as writing int(char), eg. more enoying code.

            Comment

            • anon

              #7
              Re: 8 bit integer type

              zacariaz@gmail. com wrote:
              On 29 Aug., 13:24, anon <a...@no.nowrot e:
              >zacar...@gmail .com wrote:
              >>On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia. comwrote:
              >>>On 2007-08-29 11:45, zacar...@gmail. com wrote:
              >>>>typedef char int(myint8);
              >>>>the above is realy what i wanna do, but ofcourse it cant be done this
              >>>>way. I have looked around for a 8 bit integer type, but no luck. the
              >>>>int8_t and simular still acts like chars.
              >>>>Yes i know it a stupid little thing, but im getting tired of writing
              >>>>int(my8bitv ar); all the time, and if there is a type that doesnt act
              >>>>like a char, i wanna know.
              >>>In what way does a char differ in behaviour from an int, except for the
              >>>range of values it can hold?
              >>>--
              >>>Erik Wikström
              >>Of course it doesnt differ much, but it does differ, fx. what do you
              >>think happened when i first head about the stdint.h and wanted to try
              >>out the uint8-t?
              >>@code
              >>uint8_t var = 7;
              >>std::cout << var;
              >>@code
              >>BEEP! it said.
              >>Imagine my surprise. and integer type making funny noises?
              >>Yes, it is a tiny little wee wee thing that nobody care about, but
              >>still it enoys me having to write
              >>std::cout << int(var);
              >>Yes, it is only 5 extra letter, well that depends, but the goal of
              >>this post was only to make certain that a real 8 bit integer type or
              >>an easy soluton doesnt allready excist.
              >struct int8bit
              >{
              > unsigned int number : 8;
              >>
              >}
              >>
              >then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -
              >>
              >- Vis tekst i anførselstegn -
              >
              ah yes, two problems reamins however.
              1. How much space does this new type use in memory? i mean is it just
              an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?
              It would take 32 bit memory, but it would be 8-bit unsigned int.
              2. this vould not be used as a regular type but would have to be
              called like int8bit.number, this is not that important, but really it
              would be tha same as writing int(char), eg. more enoying code.
              You could encapsulate it in a class.

              Comment

              • zacariaz@gmail.com

                #8
                Re: 8 bit integer type

                On 29 Aug., 14:52, anon <a...@no.nowrot e:
                zacar...@gmail. com wrote:
                On 29 Aug., 13:24, anon <a...@no.nowrot e:
                zacar...@gmail. com wrote:
                >On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia. comwrote:
                >>On 2007-08-29 11:45, zacar...@gmail. com wrote:
                >>>typedef char int(myint8);
                >>>the above is realy what i wanna do, but ofcourse it cant be done this
                >>>way. I have looked around for a 8 bit integer type, but no luck. the
                >>>int8_t and simular still acts like chars.
                >>>Yes i know it a stupid little thing, but im getting tired of writing
                >>>int(my8bitva r); all the time, and if there is a type that doesnt act
                >>>like a char, i wanna know.
                >>In what way does a char differ in behaviour from an int, except for the
                >>range of values it can hold?
                >>--
                >>Erik Wikström
                >Of course it doesnt differ much, but it does differ, fx. what do you
                >think happened when i first head about the stdint.h and wanted to try
                >out the uint8-t?
                >@code
                >uint8_t var = 7;
                >std::cout << var;
                >@code
                >BEEP! it said.
                >Imagine my surprise. and integer type making funny noises?
                >Yes, it is a tiny little wee wee thing that nobody care about, but
                >still it enoys me having to write
                >std::cout << int(var);
                >Yes, it is only 5 extra letter, well that depends, but the goal of
                >this post was only to make certain that a real 8 bit integer type or
                >an easy soluton doesnt allready excist.
                struct int8bit
                {
                unsigned int number : 8;
                >
                }
                >
                then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -
                >
                - Vis tekst i anførselstegn -
                >
                ah yes, two problems reamins however.
                1. How much space does this new type use in memory? i mean is it just
                an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?
                >
                It would take 32 bit memory, but it would be 8-bit unsigned int.
                >
                2. this vould not be used as a regular type but would have to be
                called like int8bit.number, this is not that important, but really it
                would be tha same as writing int(char), eg. more enoying code.
                >
                You could encapsulate it in a class.- Skjul tekst i anførselstegn -
                >
                - Vis tekst i anførselstegn -
                not that it matters much cause the solution is not what im looking
                for, but what do you mean by "encapsulat e in a class"?

                Comment

                • anon

                  #9
                  Re: 8 bit integer type

                  zacariaz@gmail. com wrote:
                  >>2. this vould not be used as a regular type but would have to be
                  >>called like int8bit.number, this is not that important, but really it
                  >>would be tha same as writing int(char), eg. more enoying code.
                  >You could encapsulate it in a class.
                  >
                  not that it matters much cause the solution is not what im looking
                  for, but what do you mean by "encapsulat e in a class"?
                  >
                  You can do the same for char (or unsigned char, not sure what you
                  using). By encapsulating it in a class, you would have to overload all
                  operators you are going to use (+, - , etc) and you would have to write
                  operator<< for that class. That way you would not have to cast when
                  sending to a stream.

                  Comment

                  • Frank Birbacher

                    #10
                    Re: 8 bit integer type

                    Hi!

                    zacariaz@gmail. com schrieb:
                    Yes, it is a tiny little wee wee thing that nobody care about, but
                    still it enoys me having to write
                    std::cout << int(var);
                    Yes, it is only 5 extra letter,
                    which can be reduced, but would also reduce the verbosity:

                    std::cout << +var;

                    The unary operator + will implicitly cast the value to int. Hard to
                    read, though, so it's not good for maintenance.

                    Frank

                    Comment

                    • Geoff

                      #11
                      Re: 8 bit integer type

                      Wouldn't compilers still align data on word or half-word bounderies in
                      memory, so using a char doesn't really save any bits?

                      Or I could be imagining things.

                      --n



                      "Frank Birbacher" <bloodymir.crap @gmx.netwrote in message
                      news:5jmcolFb43 aU1@mid.dfncis. de...
                      Hi!
                      >
                      zacariaz@gmail. com schrieb:
                      >Yes, it is a tiny little wee wee thing that nobody care about, but
                      >still it enoys me having to write
                      >std::cout << int(var);
                      >Yes, it is only 5 extra letter,
                      >
                      which can be reduced, but would also reduce the verbosity:
                      >
                      std::cout << +var;
                      >
                      The unary operator + will implicitly cast the value to int. Hard to
                      read, though, so it's not good for maintenance.
                      >
                      Frank

                      Comment

                      • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

                        #12
                        Re: 8 bit integer type

                        On 2007-08-31 05:59, Geoff wrote:
                        "Frank Birbacher" <bloodymir.crap @gmx.netwrote in message
                        news:5jmcolFb43 aU1@mid.dfncis. de...
                        >Hi!
                        >>
                        >zacariaz@gmail. com schrieb:
                        >>Yes, it is a tiny little wee wee thing that nobody care about, but
                        >>still it enoys me having to write
                        >>std::cout << int(var);
                        >>Yes, it is only 5 extra letter,
                        >>
                        >which can be reduced, but would also reduce the verbosity:
                        >>
                        >std::cout << +var;
                        >>
                        >The unary operator + will implicitly cast the value to int. Hard to
                        >read, though, so it's not good for maintenance.
                        Please don't top-post and don't quote signatures.
                        Wouldn't compilers still align data on word or half-word bounderies in
                        memory, so using a char doesn't really save any bits?
                        >
                        Or I could be imagining things.
                        Yes you are, you are imagining that all computers work the same way,
                        imagine for example a computer that can align on half-word boundaries
                        and have a 16 bit word, that means no padding and no loss.

                        --
                        Erik Wikström

                        Comment

                        Working...