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
    21,632
    That is one way (though you probably meant "I assigned zero to the char").
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,632
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    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