Thread: How many bits are '1' in an integer variable?

  1. #46
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by itsme86
    No. The << and >> operators are more equivalent to SHL and SHR. The difference being ROR and ROL slap the shifted-off bit back on the other end, kind of like a conveyer belt.

    I wish you'd stop spreading bad information. If you don't know the answer, don't make it seem like you do.
    Well I am not to familiar with the intel instruction set, I was just making the point that bit shifting operations are available in C, MacNilly mentioned these instructions so I assumed they are appropiate, and you may well be able to find a solution incorperating them.
    Any way the fact they slap bit back on the end like a conveyer belt would not be an issue in anycase because you only test each bit once, there is a loop counter which counts the number of bits being tested so its not a problem at all.
    Last edited by esbo; 09-13-2006 at 02:21 PM.

  2. #47
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Salem
    > The C >> and << commands are the equivilant of ROR and ROL
    No they are not.
    ROL would (in 8 bits) turn 0x80 into 0x01, where the C operator would turn it into 0
    << and >> propagate zeros (mostly), not the bits which fall off the end..

    I was merely making the point that C has bit shifting operations, and that an equivilant effect could be achieved in C, whether he chose the most appropiate bit shift operation was not the point.
    Last edited by esbo; 09-13-2006 at 02:22 PM.

  3. #48
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by esbo
    Well I am not to familiar with the intel instruction set, I was just making the point that bit shifting operations are available in C, MacNilly mentioned these instructions so I assumed they are appropiate, and you may well be able to find a solution incorperating them.
    MacNilly mentioned no such thing. Stop trying to wiggle out of admitting that you're posting nonsense. If you're not familiar with the IA-32 instruction set, don't assume you mean what ROR and ROL mean.

    Any way the fact they slap bit back on the end like a conveyer belt would not be an issue in anycase because you only test each bit once, there is a loop counter which counts the number of bits being tested so its not a problem at all.
    Not for the loop method. But if you care to read the link Salem posted, you'll see it mentioned that, using rotate instructions, there's an even better method than those coded out. (Admittedly, MacNilly's method would work with shifting and gain no advantage from rotating. Not my point.)

    I was merely making the point that C has bit shifting operations, and that an equivilant effect could be achieved in C, whether he chose the most appropiate bit shift operation was not the point.
    If that is your point, you would do well to actually say so. What you said, though, was:
    The C >> and << commands are the equivilant of ROR and ROL
    And this is wrong, plain and simple.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #49
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by CornedBee
    MacNilly mentioned no such thing. Stop trying to wiggle out of admitting that you're posting nonsense. If you're not familiar with the IA-32 instruction set, don't assume you mean what ROR and ROL mean.
    He introduced the ROR and ROL to the discussion, not me, I merely used them to illustrate that
    C also had bit shift operations what was the intendion of my post.

    Quote Originally Posted by CornedBee
    Not for the loop method. But if you care to read the link Salem posted, you'll see it mentioned that, using rotate instructions, there's an even better method than those coded out. (Admittedly, MacNilly's method would work with shifting and gain no advantage from rotating. Not my point.)
    You can use the ROR or ROL instructions in a loop method just as effectively as the other shift instructions mentioned, certainly if you shift the variable, not the mask as I described earlier.




    Code:
    for ( i = 0; i < sizeof(int)*8 ; i++ ) 
    count+= (mask& var>>i );
    Quote Originally Posted by CornedBee


    If that is your point, you would do well to actually say so. What you said, though, was:
    And this is wrong, plain and simple.

    If you read it out of context then yes technically it is incorrect, I admit that. However I think most people reading the thread would understand the point I was making.

    I used the word equivilent which is defined as:- "Having similar or identical effects." So no it is not identical, but it does have a similar effect for the purpose the OP intended, ie counting bits. But I think it's pointless going into an arguement over semantics the language is C not English language, I don't claim to be an expert on the English language!! Nor C for that matter, I just like to write programs that work!!

  5. #50
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by esbo
    I used the word equivilent which is defined as:- "Having similar or identical effects." So no it is not identical, but it does have a similar effect for the purpose the OP intended, ie counting bits.
    You are wrong! Now shut up! This is why everyone here gets so mad at every single post you make! You're wrong. ALL THE TIME!

    Damnit just look at what you wrote above. That's wrong too!
    "Having similar or identical effects."
    They do not have identical effects! There is no "reading out of context". All you have to do is follow the thread, and here you are being wrong again. There is no context you could fabricate that would make you right here.
    Quote Originally Posted by esbo
    But I think it's pointless going into an arguement over semantics the language is C not English language, I don't claim to be an expert on the English language!! Nor C for that matter,
    No. No it's not. The entire point of the C standard is to set up these semantics, and behaviors so you know exactly what is going to happen when you do what you're supposed to.
    Quote Originally Posted by esbo
    I just like to write programs that work!!
    Well it's a good thing you didn't say "programs that are correct", because you always are doing stupid ........, and when people call you on it, you say "I don't care! It works for me!"

    Stop polluting the forums. Stop pretending you know what you're talking about. Stay out of other people's threads, because all you do is cloud the issue.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #51
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by quzah
    No. No it's not. The entire point of the C standard is to set up these semantics, and behaviors so you know exactly what is going to happen when you do what you're
    supposed to.
    Exactly!
    Discussing semantics within the context of a programming language is more than just being pedantic. It's a necessity.

    Quote Originally Posted by esbo
    If you read it out of context then yes technically it is incorrect, I admit that. However I think most people reading the thread would understand the point I was making.
    Well, I did esbo. I understood that "the C >> and << commands are the equivalent to ROR and ROL". As such, you misinformed me.

    Which would be ok, really. Everybody makes mistakes. But the fact you do it all the time, but worst, you try to cover your tracks behind a bad excuse of "I didn't mean it like that", is what is driving everybody nuts.

    Most people do a genuine effort to help others in here. They feel their efforts jeopardized by someone that they feel have to be constantly watching because is constantly wrong and directing posters the wrong way.

    I think, esbo, this is perhaps the time for you to stop posting. Please.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #52
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    This looks done. Closed.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. Replies: 7
    Last Post: 08-19-2007, 08:10 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM