Thread: Simple Number Concatination

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

    Simple Number Concatination

    Hi

    I have two 16bit numbers (in Hex):

    0x1234

    &&

    0x2119

    I would like to splice thease two numbers into a 64bit number like so:

    0x1234000000002119

    Can any one sugest a simple way to do this?

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This seems to work:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        unsigned short int a = 0x1234;
        unsigned short int b = 0x2119;
        unsigned long long c = (unsigned long long)a << 48 | b;
        printf("%I64x\n", c); /* for standard C: "%llx\n"
        return 0;
    }
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can anyone help?
    By javalurnin in forum C Programming
    Replies: 11
    Last Post: 12-02-2009, 06:02 AM
  2. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  3. Replies: 12
    Last Post: 10-23-2006, 07:45 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Number system base M, print numbers N digits wide...
    By biterman in forum C Programming
    Replies: 12
    Last Post: 11-19-2001, 04:31 AM