• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how important is shift operators....?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Friends :
Till date I have worked all these years on Microsoft platform. Also I work on overseas projects its difficult for me to give as much time to as I wud want to prepare for THE exam.
I am struggling to understand Shift Operators and Bitwise operators. Infact I am struck. Logical and Arithmetic are juz fine for me.
My question to u is.. from point of view of exam HOW IMPORTANT is it to know these topics.. or can I juz skip. My aim is to pass it first(I am not 90+ kinda guy ...)
tks,
Ashish
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashish,
I have writeen a small program to ease the shifting thing. Change according to your req.
public class ShiftTest {
public static void main(String[] args) {

int toBeShifted = 32;
int shiftBy = 34;
System.out.println("Binary representation for " + toBeShifted + " >> " + shiftBy + ":");
System.out.println("Binary for " + Math.abs(toBeShifted) + ": " + append(Math.abs(toBeShifted)));
System.out.println("Complement of above: " + append(~Math.abs(toBeShifted)));
System.out.println("Add 1: " + append((~Math.abs(toBeShifted)) + 1));
System.out.println("Shift by " + shiftBy + "(" + shiftBy%32 +"): " + append(((~Math.abs(toBeShifted)) + 1)>> shiftBy));
System.out.println("Complement: " + append(~(((~Math.abs(toBeShifted)) + 1)>> shiftBy)));
System.out.println("Add 1: " + append((~(((~Math.abs(toBeShifted)) + 1)>> shiftBy)) + 1));
System.out.println("=: " + (toBeShifted >> shiftBy)) ;

}

static String append(int no) {

String str = "";
int length = (Integer.toBinaryString(no)).length();
for( int i = 0; i < 32 - length ; i++) {

str += "0";
}
str += Integer.toBinaryString(no);
return str;
}

}
Santhosh.
 
Ashish Agnihotri
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Santosh :
Thanks for this reply too. But I am not getting it. I mean, I would be very happy if you can comment before each print as to what is being done.. its confusing for me ( which may be quite explicit.. may be I have mental block). Now I am determined to get through to learn Shift and Bit Operators.
take ur own time to do that.. but please do it.
tks,
Ashish
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Santhosh :
Even i would appreciate if u could provide information requested by Ashish, since i m also stuck at these shift operators and this program too. Pls Let us know how important is this topic i relation to exam.
Anukampa
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ashish/Anukampa, Go thru this, it might be helpful
http://www.javaranch.com/ubb/Forum24/HTML/005999.html
 
Ashish Agnihotri
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vidya :
Thanks , although I have not read it.. ( its sunday ..) it seems with a resonably good explanation.
Can you ( or anybody also tell ...) how important are Shift Operators ( & bit ) from point of view of Exam ?
tks again,
Ashish
 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashish,
Coming back to your original question of "how important this
shift operator is from exam point of view"?-->I would say
It is better not to skip the topic as there is a chance of
getting atleast "one" question<if not two>:-)
good luck...
regds
NM
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashish,
The program basically written to solve a doubt for Vidya. She had some problems with shifting -ve number. i.e. getting binary representation for -ve number and shifting. So program gives the step by step binary representation for shifting. Pl go thru the link provided by Vidya, there we discussed this in detail. Note: This program does only >> shifting. If you want to do << or >>>, you have to change the program accordingly (Basic rules remains same). Pl let me know, if you need some more info.
Santhosh.
 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx a ton guys for all yr help. Thanx Vidya. I will go thru information and let u know if i still face any prob.
Thanx again !!
Anukampa
 
reply
    Bookmark Topic Watch Topic
  • New Topic