Thread: Quick Question

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    61

    Quick Question

    Hi There,

    I have a 16 bit number which is a reading from a register, i want to break it down so

    bit 8 =ee8
    bit7 = ee7
    bit6 = ee6

    etc

    so can later in code simple go if(ee8 = 1) ........

    whats the easiest way to asign the variables names to the specific bits in the orginal 1bit number

    thanks

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    You can't directly address a single bit in C (or most hardware for that matter).

    If you feel you must have this sugar, either write a macro or use a "bit field".

    Soma

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Or use a function to extract the relevant bit. To implement that function, look up bitwise operators.

    I wouldn't use a bit field, as the layout of bit fields is implementation defined. Although that may be a moot point, as the location of particular registers is also well outside what the standard specifies.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A quick question...
    By MarioI in forum C Programming
    Replies: 9
    Last Post: 02-10-2011, 07:36 PM
  2. quick question about log
    By newguy9 in forum C++ Programming
    Replies: 1
    Last Post: 11-22-2008, 03:21 PM
  3. Quick question
    By Stiks in forum C Programming
    Replies: 6
    Last Post: 10-10-2005, 08:35 PM
  4. Quick Question!
    By dizz in forum C++ Programming
    Replies: 14
    Last Post: 11-21-2002, 07:02 AM
  5. Quick Question
    By SinAmerica in forum C++ Programming
    Replies: 2
    Last Post: 10-23-2002, 02:28 AM