Results 1 to 7 of 7

Thread: [RESOLVED] Unsigned Char....

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Resolved [RESOLVED] Unsigned Char....

    Well, I am still reawriting my bic C++ library to C# and found an other problem. When reading one of the file format (MD2) you are supposed to read unsign chars. Is there something like that in C#? I can't find it...hmmm...any help?


    - ØØ -
    Last edited by NoteMe; Aug 20th, 2005 at 05:53 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Unsigned Char....

    Is this unsigned char 1 byte or 2? If it's 2 then you should use a UInt16. There is no unsigned 1-byte type in .NET so I'd guess you'd just have to use a Byte if it's 1 byte.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Unsigned Char....

    It is 2bytes (16bits). The same as with all the other datatypes. But I think maybe using a "string" would be better? Or what? Isn't a string 16bits in C#? And unsigned, isn't it? I can try both and see what happens.



    - ØØ -

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Unsigned Char....

    Using a char as a number was really a hack in C++. From the name, obviously it is supposed to represent a character so treating it as a number was a convenience. A UInt16, Int16 and Char are all 2 bytes in .NET but are all intended for different, specific purposes. A string in C# is a 32-bit stack reference to an object on the heap. Quite different I would say.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Unsigned Char....

    OK, I don't have my books here, and I don't have internet on the computer I am programming on right now, so I have to run back and forth, so I just looked it up on the internet at the same time as I wrote the post. Here is what I found:

    http://codemonkey.sunsite.dk/trainin...arpprimer.html
    Code:
    BUILT-IN   NAMESPACE        SIZE         VALUES
    --------   --------------   ----------    -----------
    bool       System.Boolean   1 bit         true false
    byte       System.Byte      8 bits        0 -> 255
    sbyte      System.SByte     signed byte   -128 -> 127 
    char       System.Char      16 bits       unicode txt*
    string     System.String    2 bytes/char  unicode txt*
    
    decimal    System.Decimal   2 bytes       $ currency $double     System.Double    4 bytes       320 sig places
    float      System.Single    2 bytes       32 sig places
    int        System.Int32     2 bytes       -65363 -> +65363
    uint       System.UInt32     long       System.Int64     4 bytes
    ulong      System.UInt64 short      System.Int16     1 byte
    ushort     System.UInt16 
    object     System.Object --------   --------------   ----------    -----------
    BUILT-IN   NAMESPACE        SIZE         VALUES
    I guess that page is wrong then, or maybe my big sick bloaty head missunderstands it. But to be honest, I think it depends on how it has been all ready used. If they are using "unsigned char" as a number then I guess UInt16 is the right one, but if they are using it as a char then I guess string might pull it off, unless you are 100% right, and that web page or I am missunderstanding it... (the latter one are very likely today...I bet my head is on the size of a hot air baloon on the end of the day anyway..)


    - ØØ -
    Last edited by NoteMe; Aug 20th, 2005 at 02:01 PM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Unsigned Char....

    I'm not sure where the author of that page got there information but I believe that it is incorrect. For a start, they say that the an int is 2 bytes and ranges from -65363 to 65363. The help topic for the int type clearly states that an int is 32 bits, or 4 bytes, in size and ranges from -2,147,483,648 to 2,147,483,647. Given that the int type is implemented using the System.Int32 structure, the name alone would suggest that it is 32-bit or 4-byte. The same goes for the Int16, which is 16-bit or 2-byte, not 1-byte. Also, the System.Boolean is a bona fide structure. It is not represented by a single bit as that page suggests. I'm afraid that that section at least of that page is complete cr*p.

    Edit:
    The bit about the string type is cr*p too. The System.String class is not directly related to the System.Char structure. A char is stored on the stack, while a string is a stack reference to a heap object. If you're working on a 32-bit machine then I believe that all reference variables are 32-bit, or perhaps I'm wrong and they are transalted from 16-bit aliases. I doubt that though.
    Last edited by jmcilhinney; Aug 20th, 2005 at 07:54 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Unsigned Char....

    Well....I think it is working now...but I can't see anyting on the screen at the moment, so I have to make a camera class first. And with my bloaty head it will probably take a few days to get that far...

    But thanks for all your time and help. I guess that page is outdated...and I will make sure I don't bookmark it at work..


    Thanks
    - ØØ -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width