Thread: HELP: uint16_t and >> operator used in following program

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    3

    HELP: uint16_t and >> operator used in following program

    what does "uint8_t" or "uint16_t" mean?
    Can you tel me output of following statement if you can then please explain ?

    TWI_SLA_CAM=0xC0
    uint8_t sla;
    uint16_t eeaddr=0x12;
    sla = TWI_SLA_CAM |(((eeaddr >> 8) & 0x07) << 1);

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    uint8_t is unsigned type containing 8 bits (on most compilers unsigned char will do)
    uint16_t is unsigned type containing 16 bits - on most compilers unsigned short will do the work

    What do YOU think will be the output?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    3

    Unhappy

    i am not able to get wat
    "eeaddr>> 8"
    do ,bcoz eeaddr =0x12 even after being uint16_t

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    3
    I am unable to figure out how a uint16_t eeaddr be shifted to right by 8 bits, becoz the value stored in eeaddr is 0x12, thus shifting it by 8 bits gives 0.
    and finally gives sla=0xc0; that is TWI_SLA_CAM

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    Quote Originally Posted by pvr_3 View Post
    I am unable to figure out how a uint16_t eeaddr be shifted to right by 8 bits, becoz the value stored in eeaddr is 0x12, thus shifting it by 8 bits gives 0.
    and finally gives sla=0xc0; that is TWI_SLA_CAM
    So? What is the problem with this? Seems to be correct analisys.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. overloaded >> operator problem
    By quizkiwi in forum C++ Programming
    Replies: 7
    Last Post: 07-19-2005, 03:27 PM
  2. C++ >> Standard Library >> Header File
    By hrk2006 in forum C++ Programming
    Replies: 2
    Last Post: 06-24-2003, 08:30 PM