Results 1 to 3 of 3

Thread: Reading a decimal value stored in char

  1. #1
    Join Date
    Apr 2014
    Posts
    14
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Reading a decimal value stored in char

    I have the following QByteArray
    snap.png
    For Message[3] I want to get the decimal value 201 and not -51. How do I do that? And where did this -51 come from?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Reading a decimal value stored in char

    The byte can be interpreted as either an 8 bit unsigned/positive number or a 7bit signed number.

    -55 is the two complement of 201 (255 - 201 + 1)

    If you assign the value to a uchar then its value will be 201 since this removes the ambiguity.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Miss Engineer (28th May 2014)

  4. #3
    Join Date
    Apr 2014
    Posts
    14
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Reading a decimal value stored in char

    It worked!
    I have been working on a project using C++ and QT, both of which I've never used before.. When I'm really stuck, I know this forum will be my rescue! Thanks from the heart!

    Quote Originally Posted by anda_skoa View Post
    The byte can be interpreted as either an 8 bit unsigned/positive number or a 7bit signed number.

    -55 is the two complement of 201 (255 - 201 + 1)

    If you assign the value to a uchar then its value will be 201 since this removes the ambiguity.

    Cheers,
    _

Similar Threads

  1. Char Followed by a Char is illegal (qglobal.h)
    By saad_saadi in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2014, 14:19
  2. Replies: 2
    Last Post: 3rd July 2012, 17:42
  3. How to convert unsigned char[] to char *?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 29th April 2011, 09:58
  4. reading in image from 24bit char*
    By cbeall1 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2006, 01:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.