tag:blogger.com,1999:blog-8712770457197348465.post3937267659934328..comments2015-05-28T19:59:43.577-07:00Comments on Javarevisited: Bitwise and BitShift Operators in Java - AND, OR, XOR, Signed Left and Right shift Operator ExamplesJavin Paulhttps://plus.google.com/114528699166048052030noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-8712770457197348465.post-2682022962140025452014-06-29T09:24:38.660-07:002014-06-29T09:24:38.660-07:00Meherprasad ... these are binary operators .. i.e....Meherprasad ... these are binary operators .. i.e. powers of 2. If you want to do general math, then don't use these operators. (I.e. just do /= 3 or *= 3 instead.)<br /><br />Or ... invent a base-3 based computer, where each bit represents 3 numbers, then I guess << 1 would be a *= 3 for you ;)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-91583322375126783142014-06-01T00:08:15.393-07:002014-06-01T00:08:15.393-07:00how to multiply by 3 or divide by 3 using bitwise ...how to multiply by 3 or divide by 3 using bitwise operators ?Meherprasad cholkerhttp://www.blogger.com/profile/00460130365473558352noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-41509104967682778582014-05-12T04:58:45.253-07:002014-05-12T04:58:45.253-07:00I am commenting here since most of you have confus...I am commenting here since most of you have confusion with the ~2:<br />Explanation:<br />int number = 2 will store 2 as a 32 bit integer value: 00000000000000000000000000000010<br />When you do ~2, the bits will be inverted i.e 1 will become 0 and vice versa. The inverted number will be 11111111111111111111111111111101<br />This number is in 2's complement form represent -3.<br />Since int Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-5087782282768116852014-02-25T19:13:43.792-08:002014-02-25T19:13:43.792-08:00The ~ of 2(0010) is 1101 which is -5. Right? - Wro...The ~ of 2(0010) is 1101 which is -5. Right? - Wrong it is -3.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-56612711932105089682014-02-18T17:34:52.056-08:002014-02-18T17:34:52.056-08:00The ~ of 2(0010) is 1101 which is -5. Right?
The ~ of 2(0010) is 1101 which is -5. Right?<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-72715967651678884372013-10-13T16:13:53.509-07:002013-10-13T16:13:53.509-07:00You should probably update your comments here. You...You should probably update your comments here. You have right shifts (with and without) sign saying that the answer should be 16. Obviously 1000 right shifted with sign is 1100 which is your -4 (in 2's complement form). I think you just copied the comments over and forgot to change them.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-37345047608068054372013-10-11T14:57:05.809-07:002013-10-11T14:57:05.809-07:00The ~ of int 2 should be more like 111111111111111...The ~ of int 2 should be more like 1111111111111111111111111111101 not 1101 or -3 as you say since ints are 32 bit. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-61775614461923793212013-10-08T06:44:52.818-07:002013-10-08T06:44:52.818-07:00I have two different variables defined as byte e.g...I have two different variables defined as byte e.g.<br />byte a;<br />byte c;<br />a = a|c;<br />I have to do the Or operations between them but unfortunatelly does not give the right one. it responds always different values. I wrote a function but nothing changes. Any idea.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31726643956875106102013-05-31T08:58:16.811-07:002013-05-31T08:58:16.811-07:00For positive number it fills with zero and for neg...For positive number it fills with zero and for negative numbers it fills with 1.<br /><br />Please check this one? is it true or reverse is true?<br /><br />Rambabu Posahttp://www.blogger.com/profile/10299744564607461366noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7153804546117430932013-03-21T00:10:56.992-07:002013-03-21T00:10:56.992-07:00@Anonymous, good catch, you are correct, I actuall...@Anonymous, good catch, you are correct, I actually meant 8 >> 1. ThanksJavin @ Override Error in Eclipse Java 5http://javarevisited.blogspot.com/2013/02/must-override-superclass-method-java-eclipse.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31414874473419918492013-03-19T23:14:07.674-07:002013-03-19T23:14:07.674-07:00"then its equivalent of shifting bits 33%32 o..."then its equivalent of shifting bits 33%32 or just 1 time. e.g. 8 >> 33 is equal to 8 >> 33"<br />Don't you mean 8 >> 33 is equal to 8 >> 1Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-44988371238968412392013-03-18T06:05:15.259-07:002013-03-18T06:05:15.259-07:00@Sergey Rogov, you are absolutely correct, that a ...@Sergey Rogov, you are absolutely correct, that a typo. Thanks for pointing that out.Javin @ method override error in eclipse java 5http://javarevisited.blogspot.com/2013/02/must-override-superclass-method-java-eclipse.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-14393862820635226272013-03-14T23:21:15.930-07:002013-03-14T23:21:15.930-07:00>> 1's complement of 10 would be 01. and...>> 1's complement of 10 would be 01. and 2's complement of 10 would be 10+1 = 11 (all in binary).<br />----------<br /><br />Hm, two's compliment of 10 will be 01+1, which is 10. Right?<br />Sergey Rogovhttp://www.blogger.com/profile/01093770973064557805noreply@blogger.com