Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2011, 12:58 PM
Registered User
 
Join Date: Feb 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question regarding bitwise operators on page 66

Hi there.

I was wondering if someone could explain the example on page 66 for me, cause I don't understand it

On page 66 it says that the number 5 in its full binary representation is represented as:

000000000000000000000000000000101

I understand that, but then it says that -5 is represented as:

111111111111111111111111111111011

This I don't understand. How is the above representation equal to -5? Isn't this calculated as 1*(2^0) + 1 * (2^1) + 0 * (2^2) (calculating from left to right) for which the sum would result in a huge number and not -5, or what am I missing here?

And then, continueing from the example, these two representations get summed:

000000000000000000000000000001010
+ 111111111111111111111111111111011
= 1000000000000000000000000000000101

Where does the extra 1 to the left come from, and how should I interpret that? Obviously, the way I understood it, I would calculate this to a decimal value this way:

1*(2^32) + ... 1*(2^2) + 0 * (2^1) + 1*(2^0)

Which would give in decimal:

4294967296 + 4 + 1 = 4294967302 which obviously is not correct, as this is not the same as subtracting 5 from 10.

I'm sorry if this is a stupid question, I just started on programming, and I really can't see what I've missed here.

Love the book by the way, it is awesomely well written.
 
Old March 30th, 2011, 03:07 PM
Registered User
 
Join Date: Jan 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bahr, it is not a stupid question. Just a basic one. You will need to read about "two's complement" arithmetic in a first-year programming book. You might be able to read enough on a web site like:
http://igoro.com/archive/why-compute...os-complement/

http://mathforum.org/library/drmath/view/54344.html

That should explain it better than I could.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page 66-67, app crash chillbumps BOOK: Beginning iPhone SDK Programming with Objective-C 8 June 25th, 2011 08:15 AM
BITWISE SHIFT OPRATION kulfi BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 0 May 30th, 2010 11:42 AM
Bitwise and Access owain SQL Language 10 June 8th, 2006 10:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.