Thread: bitwise problems...cm11a protocol.

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    88

    bitwise problems...cm11a protocol.

    hi. im not too good with bitwise operators and im having some trouble with cm11a programming.


    #define HOUSE_A 0x06
    ...
    #define DEVICE_B 0x0E

    house and device go up to P but im using this as an example.

    how would i turn 0x06 and 0x0E into 0x6E?

    i was thinking left shift the 6 and add in the E but that didnt work. any help? links?

    many thanks.

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    88
    found it myself, no bitwise

    multiply 0x6 by 16 and add e to that. problem solved.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code:
    (HOUSE << 4) | DEVICE
    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.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    88
    thanks, is yours better in some way?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You asked
    > i was thinking left shift the 6 and add in the E but that didnt work

    I answered

    And next time you have a "it didn't work", be less vague and post what didn't work

    > is yours better in some way?
    As far as the executable code is concerned, I doubt it makes a difference
    As far as the overall readability of the code - perhaps bitwise ops make more sense than arithmetic ops
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Questions
    By someprogr in forum C Programming
    Replies: 8
    Last Post: 12-14-2008, 06:45 PM
  2. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  3. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  4. bitwise operations with double
    By henry_kay in forum C Programming
    Replies: 2
    Last Post: 10-03-2007, 04:57 AM
  5. Characters into bitwise ints
    By Code Zer0 in forum C++ Programming
    Replies: 9
    Last Post: 04-24-2003, 08:34 AM