LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-14-2004, 11:14 AM   #1
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Slackware 11.0 [both lap & pc] WinXP
Posts: 164

Rep: Reputation: 30
Java [ Bitwise "~" question on process ]


whats is the process to get the values with this bitwise option, as far as ive searched on the internet all i get is what ever the value is, it gives a number bigger and negative

Ex.

Bitwise and "~"

~3 <<< what i do is turn this to Binary

0 0 0 0 1 1


and as far as i know all it does it just turns the values arround or somewhat like that and i get "-4" for an ouput, and what i want to know is what is the process, in other words, what is the whole cycle into getting that -4, if anyone can help me, i would really appreciate it, im in a UIL Class and we dont get this for crap...
thanx

Last edited by k1ll3r_x; 10-14-2004 at 11:17 AM.
 
Old 10-14-2004, 11:20 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
This site should answer your questions:
http://www.vb-helper.com/tutorial_twos_complement.html

The x86 processor uses twos complement to represent negative numbers, and ~3 is 3 with all the bits reversed..
For example:
00000011 = 3
11111100 = ~3

And if you look at how twos complement works you'll see that 11111100 is -4.
 
Old 10-14-2004, 11:36 AM   #3
WhiteChedda
Member
 
Registered: Aug 2003
Location: Florida
Distribution: Mandrake 9.1 for now
Posts: 205

Rep: Reputation: 30
Re: Java [ Bitwise "~" question on process ]

Quote:
Originally posted by k1ll3r_x
whats is the process to get the values with this bitwise option, as far as ive searched on the internet all i get is what ever the value is, it gives a number bigger and negative

Ex.

Bitwise and "~"

~3 <<< what i do is turn this to Binary

0 0 0 0 1 1


and as far as i know all it does it just turns the values arround or somewhat like that and i get "-4" for an ouput, and what i want to know is what is the process, in other words, what is the whole cycle into getting that -4, if anyone can help me, i would really appreciate it, im in a UIL Class and we dont get this for crap...
thanx
Bitwise negate or NOT simpy turns teh bits that are on off and teh bits that are off, on.
thus in your example you would have
1 1 1 1 0 0

Mathmatically, the highest bit is negative IF the data is signed. By default I beleive most constants are considered signed in most langauges.

for simplicity I will work with 4 bits, you usually work with 16 or 32, but. I am too lazy.

so if we have a signed 4 bit binary number

then
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111

the last bit has a negative value which makes 1000 equivalent to -8.
Since the other bits are positive numbers, if we have 1001

then we have -8 + 1 which is -7 much taht same way that with 0011 we have 2 + 1.

given 0000 the negate of this is 1111 which is -8 + 7 or -1.

Given 3 is 0011 in binary and you take the negate you get 1100 in binary which is -8 + 4 or -4.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 04:08 PM
User "list" running process "python" TroelsSmit Linux - Newbie 2 02-22-2005 04:55 AM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
I cannot use "java chat". Browser says plugin required "x-java-vm". jdruin Linux - Software 4 04-18-2004 05:44 PM
Java does "age" or "Age" matter when declaring an Int?? Laptop2250 Programming 3 10-13-2003 12:34 PM


All times are GMT -5. The time now is 11:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration