• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

C# interview question

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    C# interview question

    Had a tech test today which was in the main ok. One question though did my head in, I was asked something like:

    int i = 500;
    i = i << 4;

    Tell us what i is.

    What the hell is the << operator, its probably something dead obvious but I seem to have gone through my career without using << ?

    #2
    Originally posted by Durbs View Post
    Had a tech test today which was in the main ok. One question though did my head in, I was asked something like:

    int i = 500;
    i = i << 4;

    Tell us what i is.

    What the hell is the << operator, its probably something dead obvious but I seem to have gone through my career without using << ?
    It means the 'the' is definitely over here...

    the <<

    Comment


      #3
      I never used this in real life.

      --
      int i = 500;

      Console.WriteLine("Base2: "+ Convert.ToString(i, 2));

      i = i << 4;

      Console.WriteLine("Base2: " + Convert.ToString(i, 2));
      Console.WriteLine("Decimal: " + i);
      --

      It outputs:

      --
      Base2: 111110100
      Base2: 1111101000000
      Decimal: 8000
      --

      C# Bitwise Shift Operators

      Comment


        #4
        Ah, its the left-shift operator, found its name, so

        int 500 binary = 111110100

        Shift left 4 = 1111101000000 = 8000.

        Ah well, got that question wrong then.

        Comment


          #5
          Originally posted by sog View Post
          I never used this in real life.

          --
          int i = 500;

          Console.WriteLine("Base2: "+ Convert.ToString(i, 2));

          i = i << 4;

          Console.WriteLine("Base2: " + Convert.ToString(i, 2));
          Console.WriteLine("Decimal: " + i);
          --

          It outputs:

          --
          Base2: 111110100
          Base2: 1111101000000
          Decimal: 8000
          --

          C# Bitwise Shift Operators
          Ta, I'd just found similar as you posted.

          Same here, not used that in anger so dont really feel bad about getting that question wrong.

          Comment


            #6
            Anyone got a real world example where it would be useful?

            Comment


              #7
              Originally posted by Durbs View Post
              Had a tech test today which was in the main ok. One question though did my head in, I was asked something like:

              int i = 500;
              i = i << 4;

              Tell us what i is.

              What the hell is the << operator, its probably something dead obvious but I seem to have gone through my career without using << ?
              I had to look it up as well, and I'm an experienced .net developer. I can't think of a practical application for that operand when you have easier access to floating point arithmetic anyway. Even when you're using bitwise operators to encapsulate several Boolean values into a readily-transferable binary number (which is about the only time I get into mucking around with individual bits), the Shift operator doesn't come into play.

              Sounds like the sort of meaningless trick question technical interviewers only ever ask when they want to feel clever, or that they think will impress their non-technical boss that is also on the interview panel.

              Comment


                #8
                Originally posted by k2p2 View Post
                Anyone got a real world example where it would be useful?
                Dunno, but they are twats for putting that in an interview, fair threw me off my stride it did.

                Googling about, it seems more associated with very low level development which as a VB/C#'er I dont touch. Do we have any Level 75 Dark Mages in the house?

                Comment


                  #9
                  Originally posted by Gentile View Post
                  Sounds like the sort of meaningless trick question technical interviewers only ever ask when they want to feel clever, or that they think will impress their non-technical boss that is also on the interview panel.
                  Yeah, it was that kind of interview, it kicked off gently with asking me to explain anti-patterns with a smug look. Went ok though (I hope!).

                  Comment


                    #10
                    Originally posted by Durbs View Post
                    Dunno, but they are twats for putting that in an interview, fair threw me off my stride it did.

                    Googling about, it seems more associated with very low level development which as a VB/C#'er I dont touch. Do we have any Level 75 Dark Mages in the house?
                    Found this.

                    I assume you're not writing this sort of stuff, so definitely a knobhead interviewer.

                    Comment

                    Working...
                    X