Thread: Bit wise operators

  1. #1
    Registered User
    Join Date
    Feb 2005

    Bit wise operators


    I have a program I need to write using only the operators:
    ! ~ & ^ | + << >>
    I can not use any loops.

    The problem is to return 1 is x > 0 and return 0 otherwise. I can figure out the positive numbered ones, just by flipping the bits and shifting and adding one, but I don't really understand when a number is negative. How can you tell when a a byte or 32 bits is positive or negative?


  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Look into two's compliment. Most likely that is how your system represent's negative numbers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 32 bit to 64 bit Ubuntu
    By Akkernight in forum Tech Board
    Replies: 15
    Last Post: 11-17-2008, 03:14 AM
  2. Replies: 7
    Last Post: 12-10-2004, 08:18 AM
  3. bit patterns of negtive numbers?
    By chunlee in forum C Programming
    Replies: 4
    Last Post: 11-08-2004, 08:20 AM
  4. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM
  5. bit conversions
    By wazilian in forum C Programming
    Replies: 4
    Last Post: 10-25-2001, 08:59 PM