2 uint8_t to a uint16?

This is a discussion on 2 uint8_t to a uint16? within the C Programming forums, part of the General Programming Boards category; Hi I'm looking for a way to take two uint8_t values and place them in a Uint16_t... Code: uint8_t bob ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    58

    Question 2 uint8_t to a uint16?

    Hi

    I'm looking for a way to take two uint8_t values and place them in a Uint16_t...

    Code:
    uint8_t bob 0xDD;
    uint8_t fred 0xFF;
    
    uint16_t tom;
    
    tom = ???
    The end result being:

    Tom: 0xDDFF

    Has any one got any ideas?

    Cheers

    David

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    tom = bob;
    tom <<= 8;
    tom |= fred ;
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. concatenating two bytes into an uint16
    By davo666 in forum C Programming
    Replies: 11
    Last Post: 01-07-2009, 11:43 PM
  2. Kind Soul Needed: Help with Pointer Code Cleanup
    By gmrobert in forum C Programming
    Replies: 5
    Last Post: 08-30-2007, 10:15 AM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM

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