Thread: uint16_t and uint32_t question!

  1. #1
    Registered User
    Join Date
    Jun 2019
    Posts
    2

    uint16_t and uint32_t question!

    Hi,
    I am getting confused between uint16 and uint32.
    uint16 has to 2 bytes[16 bits] and uint32 has 4 bytes[32 bits].

    In my problem, uint16t value= 1112 , when i convert 1112 into binary i get 10001011000 [only 12 bits are present].

    So how does the structure of 16 bits of 1112 look?

    Second question
    uint16t value= 1112

    How does (uint32_t)value look? [32 bits representation of 1112]

    Any pointers would be helpful

    Regadrs
    Niran

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,325
    > So how does the structure of 16 bits of 1112 look?
    It has 4 leading zero bits, then 10001011000

    > How does (uint32_t)value look? [32 bits representation of 1112]
    It has 20 leading zero bits, then 10001011000
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    26,942
    Quote Originally Posted by NiranjanRavi199
    uint16 has to 2 bytes[16 bits] and uint32 has 4 bytes[32 bits].
    You should be aware that while it is conventional to say that a byte is 8 bits, in C the number of bits in a byte is denoted by CHAR_BIT, and while it must be at least 8, it could be larger.

    Quote Originally Posted by NiranjanRavi199
    So how does the structure of 16 bits of 1112 look?
    You're dealing with unsigned integers so that's trivial: fill in the remaining leading bits with 0s.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,850
    Any pointers would be helpful
    Code:
    int *foo;
    I couldn't help myself...
    Fact - Beethoven wrote his first symphony in C

  5. #5
    Registered User
    Join Date
    Feb 2019
    Posts
    437
    Quote Originally Posted by click_here View Post
    Code:
    int *foo;
    i couldn't help myself...
    bwahahahahaha!

  6. #6
    Registered User
    Join Date
    Jun 2019
    Posts
    2
    Thank you for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ((uint32_t)(~0UL)) ??
    By frs in forum C Programming
    Replies: 8
    Last Post: 09-18-2010, 12:21 PM
  2. Backwards uint16_t?
    By DavidDobson in forum C Programming
    Replies: 7
    Last Post: 05-11-2009, 09:45 AM
  3. Replies: 5
    Last Post: 03-15-2009, 06:17 AM
  4. Convert uint16_t to std::string?
    By magicalo in forum C++ Programming
    Replies: 3
    Last Post: 07-18-2008, 01:34 AM
  5. uint16_t to two uint_8 values?
    By DavidDobson in forum C Programming
    Replies: 6
    Last Post: 05-11-2008, 11:07 AM

Tags for this Thread