• (cs) in reply to Drak
    Drak:

    [Defense mode]

    I think I see what went wrong here.

    The person who made it might have been a VB6 programmer (explaining the a=a-1 type lines). In VB6 bitwise operations work with the AND and OR statements. The same ones used in IF/THEN lines. PErhaps this person tried using && and || as bitwise statements, found out it didn't work, needed to finish the job, built it this way, and is now kicking himself in the head for not taking some time to figure out bitwise ops in C#.

    [/Defense mode]

    Drak



    that's quite possible - i've done that when coming from pascal to c.
    but that was in my schoolyears, long long ago before i even had a chance to get my code to production [;)]
  • (cs) in reply to anonymous
    Anonymous:

    There is such an elitism between programmers, maybe if this guy had been given the chance to ask people around him the best approach to the solution it may not have turned out this way.

    If someone presented this to me as a solution and asked me whether I thought it was right, I would have thumped them on the forehead and told them to read the fricken documentation, come up with a real solution, then ask me. Lets see:

    A quick search of the VS.NET documentation on the local computer reveals... nothing. Apparently VS.NET's help system is easily borked. And considering that I can't even open VS.NET at the moment, It locks up. No wonder I use VC6 for my software development. Ohh Well, a quick search of MSDN online reveals:

     http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_10_9_2.asp as the first hit.

  • (cs) in reply to Mike R
    Mike R:

    Umm, lets try that with the proper search term:

    http://search.microsoft.com/search/results.aspx?view=msdn&st=b&na=82&qu=c%23+bitwise+operators&s=1

    See what you get ;) practically a list of operators to use.

  • diaphanein (unregistered) in reply to Anon

    Anonymous:
    what about

    bool isFileReadOnly(int attributes) {
      return attributes & 1;
    }

    This wouldn't compile in C# (at least with all warnings on, warnings as errors):  You don't get implicit int -> bool conversion in C#.  At a minimum you would have to cast to a bool.  Although, the typical method of doing that in this case would to do:

    (attriubtes & 1) == 1;

    I would implore anyone interested in effecient bitwise operators in .Net to take a look at the BitVector32 class (in System.Collections.Specialized).  Abstracts all this away from you.  If you're really interested in the bitwise operations, disassemble the class and take a look at how its implemented:

    <FONT color=#1000a0>public</FONT> <FONT color=#006018>bool</FONT> get_Item(<FONT color=#006018>int</FONT> bit)
    {
          <FONT color=#1000a0>return</FONT> ((<FONT color=#1000a0>this</FONT>.<FONT color=#006018>data</FONT> & <FONT color=#006018>bit</FONT>) == <FONT color=#006018>bit</FONT>);
    }
    <FONT color=#1000a0>public</FONT> <FONT color=#006018>void</FONT> set_Item(<FONT color=#006018>int</FONT> bit, <FONT color=#006018>bool</FONT> value)
    {
          <FONT color=#1000a0>if</FONT> (<FONT color=#006018>value</FONT>)
          {
                <FONT color=#1000a0>this</FONT>.<FONT color=#006018>data</FONT> |= ((<FONT color=#006018>uint</FONT>) <FONT color=#006018>bit</FONT>);
          }
          <FONT color=#1000a0>else</FONT>
          {
                <FONT color=#1000a0>this</FONT>.<FONT color=#006018>data</FONT> &= ((<FONT color=#006018>uint</FONT>) ~<FONT color=#006018>bit</FONT>);
          }
    }

    All of the operations involving getting/setting bit masks is done in one clear, concise line of code.  Theonly if else statement is used to determine whether to clear or set a bitmask. No looping, no expensive modulus operations (relatively speaking, of course).

  • Mr Sensative (unregistered) in reply to Charles Nadolski

    Charles Nadolski:
    Anonymous:
    Are you trying to say people with GED's and no degree's are stupid? I hate to break it to you buddy, but I got a GED and a 9th grade education and I can code well in oh about 16 languages..... not to mention all the stuff I know the college teachers I've met don't or people with a degree for that matter.......


    Dear Mr Sensitive:

    Carefully re-read my post.  I did not write that people with a GED are stupid.  To paraphrase myself, I would say it is understandable if somebody did not know of bitwise operators if they had not experienced a rigorous educational experience.  However, if we look at your post, your knee-jerk reaction betrays an insecurity about your educational level, despite the fact that you are a successful programmer.

    I think we can agree that on the average, person A who has just graduated from highschool will not have the foggiest notion what a bitwise operator is, but a person B with a Computer Science degree better damn well know what a bitwise operator is.

    Thanks for playing!

     

    I am not insecure about my education or lack there of. I am however very annoyed a how a lot of presumable educated people seem to think they know more than us poor uneducated people.

    On a side note, where are you from? They must have better schools there than the rest of the planet because I have met some very uninformed educated people.......

    Make peace not war [8o|]. A better way to put your orignal statement would have been: Do they have any B/C/C++/Java experiance? I know I never had need to know about & | << >> yadda yadda until I was using API in VB or doing some C..... [:#]

  • (cs) in reply to Mr Sensative
    Anonymous:

    I am not insecure about my education or lack there of. I am however very annoyed a how a lot of presumable educated people seem to think they know more than us poor uneducated people.

    On a side note, where are you from? They must have better schools there than the rest of the planet because I have met some very uninformed educated people.......

    Make peace not war [8o|]. A better way to put your orignal statement would have been: Do they have any B/C/C++/Java experiance? I know I never had need to know about & | << >> yadda yadda until I was using API in VB or doing some C..... [:#]



    Well, you are indeed correct.  There are quite a many people who go to College with absolutely no intention of getting an education.  However, the intention of the university is to expand your horizons, to question your own abilities and motives, and to of course learn from people who are far more educated and (hopefully) competent then you are.

    I can say that at my current job, I've learned a lot more programming skills in the past six months than from two years of university education.  However, had I not been to the university, I would have no been exposed to numerous methodologies that I would not have learned being pigeonholed into a job with a specific purpose.

    I would not have learned OCaml, Prolog, Artificial Intelligence, 3-D graphical programming, Matlab, Differential Equations, French Business Culture, Medieval French, several technical writing courses, Psycholinguistics, How to lead a group programming project, Assembly language, VLSI, VHDL, how to build a simple robot with basic ICs, Marketing, Chemistry, Thermodynamics, Electric and Magnetic fields.  If I hadn't taken the Advanced Placement courses in highschool then I wouldn't have known Renaissance and Englightment history of Europe, Calculus, and Mechanics and electromagnetism (using calculus).

    I took advantage of every educational opportunity available to me.  I just happened to live in a neighborhood with the best highschools in the state (Suburbs north of Chicago), and in a state with an excellent public university (UIUC).  I consider myself very well rounded, with a much more varied skill set than most programmers who go into the field.

    There are of course a very large number of students who go to the university and don't care a whit about getting an education.  College is simply "something to do after high school", and this cadre is more than willing to piss away their parents' money.  There were quite a number of people who were in Computer Engineering (my degree) who were in it only for the money.  They just copied other people's homework and used the curve to coast through all their exams.  Interestingly enough, they had no interest in *other* topics either, and just took the bare minimum of electives that their friends said were the "easiest" to pass.

    Then I have other friends who are quite intelligent, but never had the discipline to take the tough classes in high school and the discipline to get a university degree.  They are at an extreme disadvantage, because unfortunately, human resource departments put a lot of value in a piece of paper.  Google is a great learning tool, but it can't give you a degree :)

    As someone mentioned above, a university degree is a filtering tool.  You might have an Einstein wandering out there with m4d c0ding sk11lz, and you might have a complete dud (like the author of the above gem) who got a CS degree 'cause they heard you can get a cushy job with a nice income.  However, the intention of the CS degree is supposed to confirm that the individual in question has covered a broad swath of CS topics and has a keen interest in programming.
  • (cs) in reply to Duh-nonymous
    <FONT size=3>

    WTF?

    <FONT color=navy>
            for(int i=0; i<sizeof(attributes)*8-1; i++) {
                  attributes<<=1;
            }
            return (attributes<0)?1:0;
    
    <FONT color=black>

    Should just be

    <FONT color=navy>
            return ((attributes<<31)<0);
    
    </FONT></FONT></FONT></FONT>
  • (cs) in reply to Duh-nonymous
    Anonymous:

    Everyone knows (or should know) the most machine-efficient way to test a single bit it testing the sign bit: it's a single assembler instruction (lz or gz).  So to test a different bit, just left shift your argument intil the desired bit is in the sign position, then test the signedness of the argument.   Like so:

    <SIZEOF {="" i="" (attributes)*8-1=""></SIZEOF><SIZEOF {="" i="" (attributes)*8-1=""></SIZEOF>public bool IsFileReadOnly(int attributes) {
    for(int i=0; i<sizeof(attributes)*8-1; i++) {
    attributes<<=1;
    }
    return (attributes<0)?1:0;
    }


    (meant to quote this in my message above)

  • (cs) in reply to Charles Nadolski

    Couple of years ago I completed a part time computer science degree and from my recollection, there was no specific mention of bitwise operators in any of the languages covered...

  • (cs) in reply to fatgeekuk
    fatgeekuk:
    Couple of years ago I completed a part time computer science degree and from my recollection, there was no specific mention of bitwise operators in any of the languages covered...


    If you had programmed in assembly you would know what bitwise operators were. Of course, this topic are more stressed in Computer Engineering than in Computer Science :-/ Heaven forbid you would be able to understand the dissassembly panel in Visual Studio...
  • (cs) in reply to E++
    <FONT size=3>

    Quoting from E++ (f. p.o.s. forum says my quote blocks are unmatched):

    WTF?

    <FONT color=navy>
            for(int i=0; i<SIZEOF(ATTRIBUTES)*8-1; PRE < (attributes<0)?1:0; return } attributes<<="1;" { i++)><FONT color=black>
    

    Should just be

    <FONT color=navy>
            return ((attributes<<31)<0);
    

    <FONT color=#000000></FONT> 

    </FONT></FONT></FONT></FONT><FONT face=Georgia></FONT> 

    <FONT face=Georgia>--end quote</FONT>

     

    <FONT face=Georgia>A: Only if you're sure you know the size of attributes, and it will never change.</FONT>

    <FONT face=Georgia>B: <!--StartFragment -->Well, you caught the silly coding, but the code doesn't do what was intended anyway.  </FONT>
    <FONT face=Georgia>What we need is something like:</FONT>

    bool checkbit(int bitno)  // bitno from left, 0 origin
       {
       return (attributes << bitno) < 0 ? true : false;
       }


    <FONT face=Georgia>Do a little more math if you want to specify bit from the right, or by mask. </FONT>
     
  • Mr Sensative (unregistered) in reply to Charles Nadolski

    Charles Nadolski:
    fatgeekuk:
    Couple of years ago I completed a part time computer science degree and from my recollection, there was no specific mention of bitwise operators in any of the languages covered...


    If you had programmed in assembly you would know what bitwise operators were. Of course, this topic are more stressed in Computer Engineering than in Computer Science :-/ Heaven forbid you would be able to understand the dissassembly panel in Visual Studio...

    I'm sorry now that I've seen that on TV you are the SHIZNITE! 

    You made my point for me though. At least somewhat. I have experiance in place of a paper that says I might be able to do the job... To be perfectly honest though if my situation had been better I would have gotten my degree. I still plan on it. Not because having a degreee means you are a good programmer, but because some people think that's the case. Anyway let's not beat a dead horse here.

  • (cs) in reply to Mr Sensative
    Anonymous:

    Charles Nadolski:
    fatgeekuk:
    Couple of years ago I completed a part time computer science degree and from my recollection, there was no specific mention of bitwise operators in any of the languages covered...


    If you had programmed in assembly you would know what bitwise operators were. Of course, this topic are more stressed in Computer Engineering than in Computer Science :-/ Heaven forbid you would be able to understand the dissassembly panel in Visual Studio...

    I'm sorry now that I've seen that on TV you are the SHIZNITE! 

    You made my point for me though. At least somewhat. I have experiance in place of a paper that says I might be able to do the job... To be perfectly honest though if my situation had been better I would have gotten my degree. I still plan on it. Not because having a degreee means you are a good programmer, but because some people think that's the case. Anyway let's not beat a dead horse here.



    Before we beat this horse to a bloddy pulp I have one more thing to add.  Another group of people to blame are HR departments. A Resumé is an excersize of deception, and an interview is an excesize of discrimination.  Can CatBert the Evil HR guy trust that the experience you wrote down is not fabricated?  So they *have* to take your diploma into consideration.  But can the Evil HR guy really trust that diploma, if many graduates don't know bitwise operators?

    Hence why nepotism and other alternatives to the resumé-interview system are so rampant in US corporations.  "Well you see, my cousin and my ex-roommate are excellent programmers" or "So and so in the mail room is actually a genius Java programmer".  It saves the corporation money because they don't have to spend overhead and time with a long interview process, and they don't have to risk hiring a complete stranger who might only turn out semi-competent at best.
  • Yea right (unregistered) in reply to LG
    > Are you trying to say people with GED's and no degree's are stupid?

    >> It's a filtering effect: anybody, both competent and intelligent people and harmful morons
    , can be
    >> uneducated, while the process of getting a technical degree is expected to ensure that people like >> today's featured fool are rejected or improved to a decent level.

    Great idea. Unfornationally here in the real world this process doesn't quite live up to the expectations.
    The amount of fools with degrees I've had to misfortune to work with is pretty much equal to those without one. Also the fools with degrees tend to be *much worse*.

Leave a comment on “It's a Bit Defective”

Log In or post as a guest

Replying to comment #:

« Return to Article