The Bitwise complement

This is a discussion on The Bitwise complement within the C++ Programming forums, part of the General Programming Boards category; Can somebody explain me why this: ------------------------------------- #include <iostream.h> int main(void) { int a, b; a = 100; b = ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    1

    Unhappy The Bitwise complement

    Can somebody explain me why this:

    -------------------------------------
    #include <iostream.h>

    int main(void)
    {
    int a, b;

    a = 100;
    b = ~a;

    cout << a << endl;
    cout << b << endl;
    }
    -------------------------------------

    comes out as:
    100
    -101

    shouldn't it be 100 and 27?

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Do a search on google for 'two's complement'.

  3. #3
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    With Bitwise ops the ~ means opposite.

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. bitwise operations with double
    By henry_kay in forum C Programming
    Replies: 2
    Last Post: 10-03-2007, 05:57 AM
  3. C bitwise operator exercise - more like newb killer
    By shdwsclan in forum C Programming
    Replies: 3
    Last Post: 02-22-2006, 07:02 AM
  4. two's complement question
    By NetWeirdo in forum C Programming
    Replies: 1
    Last Post: 12-10-2005, 02:36 PM
  5. Characters into bitwise ints
    By Code Zer0 in forum C++ Programming
    Replies: 9
    Last Post: 04-24-2003, 09:34 AM

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