spliting 16bit variable into LSB and MSB 8 bit variables

This is a discussion on spliting 16bit variable into LSB and MSB 8 bit variables within the C Programming forums, part of the General Programming Boards category; Is there an easier / more efficient way to create an 8bit MSB and LSB pair from a 16bit variable ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    2

    spliting 16bit variable into LSB and MSB 8 bit variables

    Is there an easier / more efficient way to create an 8bit MSB and LSB pair from a 16bit variable than bit shifting and storing?

    Thanks
    ~Tim

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,767
    That is the easy way.
    And most modern processors achieve it in a single clock tick.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    2
    Quote Originally Posted by Salem View Post
    That is the easy way.
    And most modern processors achieve it in a single clock tick.
    Okay.. Thanks..

    ~T|/\/\

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21