Like Tree3Likes
  • 1 Post By laserlight
  • 2 Post By Elysia

Clearing all bits in an unsigned char

This is a discussion on Clearing all bits in an unsigned char within the C++ Programming forums, part of the General Programming Boards category; I am trying to clear all the individual bits in an unsigned char and i assigned the char to zero.I ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    118

    Clearing all bits in an unsigned char

    I am trying to clear all the individual bits in an unsigned char and i assigned the char to zero.I am not sure if thats the right way

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,801
    That is one way (though you probably meant "I assigned zero to the char").
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126
    calloc is originally from C but you can use it in C++ too.

    It puts zeros in the allocated memory chunk

    calloc - C++ Reference
    Mac OS 10.6 Snow Leopard : Darwin

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,801
    Quote Originally Posted by nacho4d
    calloc is originally from C but you can use it in C++ too.

    It puts zeros in the allocated memory chunk
    calloc is a wrong solution here both in C and C++ since its primary purpose is dynamic memory allocation. You were probably thinking of memset instead.
    sigur47 likes this.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,996
    In C++, there is std::fill instead of memset.
    Elkvis and sigur47 like this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-20-2010, 12:19 PM
  2. clearing bits using C macros
    By v333k in forum C Programming
    Replies: 11
    Last Post: 04-23-2010, 02:51 PM
  3. Char Help! "Packing " bits to a signle unsigned char
    By xxrexdartxx in forum C Programming
    Replies: 7
    Last Post: 10-11-2009, 04:45 AM
  4. Replies: 2
    Last Post: 10-06-2009, 09:37 AM
  5. cast unsigned char* to (the default) signed char*
    By Mario F. in forum C++ Programming
    Replies: 24
    Last Post: 07-27-2007, 10:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21