Thread: Help with a bit manipulation program.

  1. #16
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I did learn something today, quzah, that did surprise me. You know what it is? The people that are smart enough to help nitpick the people doing their best to help. I also learned that these forums are started with good intentions but end up being ruined by people that have no social life because all they do is insult others.
    You should have learned then that the "nit picking" is in an effort to keep people clear on what's going on. For example, there is nothing illegal with the following line of code:
    Code:
    gets( foo );
    It's perfectly legal code. It compiles. It runs. However, it's not safe code. Should I not "nit pick" people here and tell them it's fine to use this? Should I suggest people ditch other input methods when they want to just get a line from the user, in favour of gets? I mean, it's legal C.

    Look at your sig. You make it a point of how 1337 you are, because you're a "teenager" who is "correcting" people. It's apparently some point of pride you've got, but you yourself can't handle being corrected. You've been corrected a number of times this thread, and it makes you angry. No? Let's quote you some more:
    Quote Originally Posted by Brad0407
    With that anger out, I'd...
    Now then...
    Quote Originally Posted by Brad0407
    Not on machines where a char is 2 bytes.

    I also forgot to mention that if you are like Prelude and are worried that a char is actually 2 bytes, you can always remove any extra bits by simply doing this:
    Code:
    char character;
    // change all the extra bits to zero
    character = character & 255;
    Prelude didn't mention that. Maybe she didn't know or was just to busy complaining that she forgot to mention.
    The standard defines the size of a character will always evaluate to 1. ALWAYS. Here, I'll quote it, since you've apparently never seen the standard:
    6.5.3.4 The sizeof operator
    Constraints
    1 The sizeof operator shall not be applied to an expression that has function type or an
    incomplete type, to the parenthesized name of such a type, or to an expression that
    designates a bit-field member.
    Semantics
    2 The sizeof operator yields the size (in bytes) of its operand, which may be an
    expression or the parenthesized name of a type. The size is determined from the type of
    the operand. The result is an integer. If the type of the operand is a variable length array
    type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an
    integer constant.
    3 When applied to an operand that has type char, unsigned char, or signed char,
    (or a qualified version thereof) the result is 1.
    When applied to an operand that has array
    type, the result is the total number of bytes in the array.84) When applied to an operand
    that has structure or union type, the result is the total number of bytes in such an object,
    including internal and trailing padding.
    There you have it, sizeof char will always evaluate to 1. That's the entire point of sizeof. Clearly you don't understand the point of the operator.

    I suspect the reason masking off the lower portion of a multi-byte character wasn't mentioned by Prelude is because it was irrelevant to this discussion. It's just an attempt at you to prove something to people who don't care about you. I don't have time to sit around and cheer you up with little strokes to your ego. I do have time to point out when people don't understand things, like the fact that the standard denotes that CHAR_BIT is the number of bits bytes, and not just 8.


    Quzah.
    Last edited by quzah; 10-24-2005 at 05:44 PM. Reason: Making that last sentence roll off of the tongue a bit easier.
    Hope is the first step on the road to disappointment.

  2. #17
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Sorry about the comment that I've had a computer return 2 as the sizeof(char) that was actually for something completely different and I had multiplied the answer by 2. I stand corrected on that statement. However, a char is still a byte
    "In C, a character is one byte long." (Teach Yourself C, 514).
    "A char type is a single byte"(Ansi C on Unix, 63)

    A byte is no always 8 bits.
    "a byte is the smallest unit of addressable memory." (Compiler Princles, Techniques and Tools,399)

    I was, however, allowed to assume that on his machine it was 8 bits because of his original post. "8-bit binary numbers (bytes)".

    Hopefully you can't argue with that anymore.
    But I know that you'll find a way.
    Don't quote me on that... ...seriously

  3. #18
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by Brad0407
    I see you have 7,714 posts right now. I hope that at least one of them actually helped someone.
    You show know that Prelude is overflowing with knowledge. In fact it would not surprise me if she has the entire standard memorised!
    Go read the faq. Not only might you learn something (even though you seem to think you know everything anyway), but you will see that Prelude has written a majority of the faq entries.

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well, if you're going to take anything as "gospel", in regards to C, you follow the standard. There are lots of incorrect statements in books. The standard is however, what the C language is derived from, or perhaps composed from. There are lots of authors who don't have any idea what they're talking about. (What? Don't look at me like that. I didn't mention 'Mister C' by name! Yeah, you were all think of him too. Admit it. Oh no... Schildt? Yeah. I thought of him too.)

    At any rate, when I make a blanket statement around here, usually I'm referring to the standard itself. Most of the people around here with thousands and thousands of posts that post on the C forum are also. Prelude most definately is. Salem and I both have been here for more years than either of us can remember. At least seven years, I'm pretty sure.

    That being said, I am occasionally wrong. When that happens, expect very long threads with posts back and forth on the topic. It's good to be able to admit you're wrong, even if it takes one 20 posts in debate to see the point.

    But just so you know, I wasn't wrong here. You were.


    Quzah.
    Last edited by quzah; 10-24-2005 at 06:24 PM.
    Hope is the first step on the road to disappointment.

  5. #20
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    What are you still not wrong about that I didn't admit that I was wrong about? I said that sizeof(char) returns 1. I said that a byte isn't necessarily 8 bits although that is common and is what the original poster believes and I still haven't found anything that says that a char isn't 1 byte. A char is one byte and that was what it was created for. You've won the argument. You were right and I was wrong.

    The Visual Studio 6.0 MSDN Library states that a char is 1 byte. I believe that I am fully correct in saying that in the ansi C programming language a char is 1 byte.

    That is the only part of my arguement that I still hold. You have proven me wrong in all other parts.
    Don't quote me on that... ...seriously

  6. #21
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Brad0407
    That is the only part of my arguement that I still hold. You have proven me wrong in all other parts.
    I have no idea what part you're still trying to hold with. However, you should perhaps ask your English teacher for a few more lessons. You see, the words "was" and "were" refer to past tense. That is to say, if I say, "You were 4 years old.", it refers to the point in history where you were 4 years old. As such, the statements:
    Quote Originally Posted by quzah
    But just so you know, I wasn't wrong here. You were.
    Refers to the point in time where you were wrong, and I wasn't. That is to say, in this thread, you'll find points where you were wrong, and I wasn't.

    See how simple that concept is? To further the point, you'll also find points of reference where:

    Prelude was right, and you weren't.
    itsme86 was right, and you weren't.
    Dave_Sinkula was right, and you weren't.

    And lest you forget,

    I was right, and you weren't.

    Are we clear now? Here. Here's a little more salt for that. It sure is a .......... when you throw down on people who shred you, isn't it? Yeah. Learn not to do that. See, it irritates me when people come here and spit in the face of people who clearly have far more knowledge than they do. Like they have some point to prove that their penis is bigger than the people with more posts than them. You see, I don't care about you in any way, shape or form.

    I do care when you act all ........y because you've been corrected on a point, and can't handle it, and then start taking out your anger on people who's oppinion I respect. You see, a lot of them have more tact than I do, regarding people like you. But I don't care enough about you to care if I step on your toes or not.

    So perhaps next time when someone corrects you, you'll take an additional moment to think about your answer. Because I damn sure don't care if mine upsets you. And I will call you on your "answer" when you're wrong. Count on it.


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

  7. #22
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    I still think that a char is one byte. In my previous post I was trying to tell you that I finally realized that you were and are right about everything else. The reason that I originally argued was because I genuinely thought that I was right and you were wrong, but now I realise that it was the other way around. I apologize for arguing something that was wrong. You were and are right. I will check my facts in the future.
    Don't quote me on that... ...seriously

  8. #23
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Quote Originally Posted by Brad0407
    I believe that I am fully correct in saying that in the ansi C programming language a char is 1 byte.

    That is the only part of my arguement that I still hold. You have proven me wrong in all other parts.
    Funny, nobody claimed that a char wasn't 1 byte, except for you, earlier.

    Quzah, if you're been here seven years, your join date is 3 years out, or did you have a previous username?

    quzah
    Yes, yes I am.
    Join Date: Oct 2001
    Posts: 6,666

  9. #24
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by cwr
    Quzah, if you're been here seven years, your join date is 3 years out, or did you have a previous username?
    [OT]While I am somewhat curious as to time both before I was here and before the board's current incarnation, a while back I'd seen this.[/OT]
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #25
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well you see, for a while there, it seemed like they kept changing software all the time. So I got tired of resigning up. I posted for a long time with this latest board version without signing up again. Salem asked me why I didn't sign up, or something, so I finally got around to signing in again.

    But yeah, I've been here for I think at least four versions of the this forum. (By version, I mean each time they switched forum software so you had to create a new account again.

    It looks like they switched software sometime around 10-16-01, or so? No, wait, 8-30-01? Anyway, when they switched, I was here. Before that, I was here. Before that switch, I was here, and so on.


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

  11. #26
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    wow.......

    i guess i didnt need to go to the movies after all!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Bit Computation Program
    By cisokay in forum C++ Programming
    Replies: 6
    Last Post: 05-13-2005, 09:32 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM