{"id":10064,"date":"2015-07-27T01:09:45","date_gmt":"2015-07-27T05:09:45","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10064"},"modified":"2015-08-04T10:15:26","modified_gmt":"2015-08-04T14:15:26","slug":"use-bitset-with-enum-together","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10064","title":{"rendered":"Use bitset with enum together"},"content":{"rendered":"<pre>\/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book\r\n \u00a0*\u00a0\"The\u00a0C++\u00a0Standard\u00a0Library\u00a0-\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference\"\r\n \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999\r\n \u00a0*\r\n \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999.\r\n \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software\r\n \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies.\r\n \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0\"as\u00a0is\"\u00a0without\u00a0express\u00a0or\u00a0implied\r\n \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose.\r\n \u00a0*\/\r\n #include\u00a0&lt;bitset&gt;\r\n #include\u00a0&lt;iostream&gt;\r\n <strong>using\u00a0<\/strong>namespace\u00a0std;\r\n \r\n <strong>int\u00a0<\/strong>main()\r\n {\r\n \u00a0\u00a0\u00a0\u00a0\/*\u00a0enumeration\u00a0type\u00a0for\u00a0the\u00a0bits\r\n \u00a0\u00a0\u00a0\u00a0\u00a0*\u00a0-\u00a0each\u00a0bit\u00a0represents\u00a0a\u00a0color\r\n \u00a0\u00a0\u00a0\u00a0\u00a0*\/\r\n \u00a0\u00a0\u00a0\u00a0<strong>enum\u00a0<\/strong>Color\u00a0{\u00a0red,\u00a0yellow,\u00a0green,\u00a0blue,\u00a0white,\u00a0black,\u00a0\/\/...,\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0numColors\u00a0};\r\n \r\n \u00a0\u00a0\u00a0\u00a0\/\/\u00a0create\u00a0bitset\u00a0for\u00a0all\u00a0bits\/colors\r\n \u00a0\u00a0\u00a0\u00a0bitset&lt;numColors&gt;\u00a0usedColors;\r\n \r\n \u00a0\u00a0\u00a0\u00a0\/\/\u00a0set\u00a0bits\u00a0for\u00a0two\u00a0colors\r\n \u00a0\u00a0\u00a0\u00a0usedColors.set(red);\r\n \u00a0\u00a0\u00a0\u00a0usedColors.set(blue);\r\n \r\n \u00a0\u00a0\u00a0\u00a0\/\/\u00a0print\u00a0some\u00a0bitset\u00a0data\r\n \u00a0\u00a0\u00a0\u00a0cout\u00a0&lt;&lt;\u00a0\"bitfield\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0\"\u00a0&lt;&lt;\u00a0usedColors\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;&lt;\u00a0endl;\r\n \u00a0\u00a0\u00a0\u00a0cout\u00a0&lt;&lt;\u00a0\"number\u00a0\u00a0\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0\"\u00a0&lt;&lt;\u00a0usedColors.count()\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;&lt;\u00a0endl;\r\n \u00a0\u00a0\u00a0\u00a0cout\u00a0&lt;&lt;\u00a0\"bitfield\u00a0of\u00a0unused\u00a0colors:\u00a0\"\u00a0&lt;&lt;\u00a0~usedColors\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;&lt;\u00a0endl;\r\n \r\n \u00a0\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0any\u00a0color\u00a0is\u00a0used\r\n \u00a0\u00a0\u00a0\u00a0<strong>if\u00a0<\/strong>(usedColors.any())\u00a0{\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0loop\u00a0over\u00a0all\u00a0colors\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<strong>for\u00a0<\/strong>(<strong>int\u00a0<\/strong>c\u00a0=\u00a00;\u00a0c\u00a0&lt;\u00a0numColors;\u00a0++c)\u00a0{\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0the\u00a0actual\u00a0color\u00a0is\u00a0used\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<strong>if\u00a0<\/strong>(usedColors[(Color)c])\u00a0{\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/...\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n \u00a0\u00a0\u00a0\u00a0}\r\n }\r\n \r\n \/*\u00a0\r\n bitfield\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0001001\r\n number\u00a0\u00a0\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a02\r\n bitfield\u00a0of\u00a0unused\u00a0colors:\u00a0110110\r\n \r\n \u00a0*\/<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book \u00a0*\u00a0&#8220;The\u00a0C++\u00a0Standard\u00a0Library\u00a0&#8211;\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference&#8221; \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999 \u00a0* \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999. \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies. \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0&#8220;as\u00a0is&#8221;\u00a0without\u00a0express\u00a0or\u00a0implied \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose. \u00a0*\/ #include\u00a0&lt;bitset&gt; #include\u00a0&lt;iostream&gt; using\u00a0namespace\u00a0std; int\u00a0main() { \u00a0\u00a0\u00a0\u00a0\/*\u00a0enumeration\u00a0type\u00a0for\u00a0the\u00a0bits \u00a0\u00a0\u00a0\u00a0\u00a0*\u00a0&#8211;\u00a0each\u00a0bit\u00a0represents\u00a0a\u00a0color \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0enum\u00a0Color\u00a0{\u00a0red,\u00a0yellow,\u00a0green,\u00a0blue,\u00a0white,\u00a0black,\u00a0\/\/&#8230;, \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0numColors\u00a0}; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0create\u00a0bitset\u00a0for\u00a0all\u00a0bits\/colors \u00a0\u00a0\u00a0\u00a0bitset&lt;numColors&gt;\u00a0usedColors; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0set\u00a0bits\u00a0for\u00a0two\u00a0colors \u00a0\u00a0\u00a0\u00a0usedColors.set(red); \u00a0\u00a0\u00a0\u00a0usedColors.set(blue); \u00a0\u00a0\u00a0\u00a0\/\/\u00a0print\u00a0some\u00a0bitset\u00a0data \u00a0\u00a0\u00a0\u00a0cout\u00a0&lt;&lt;\u00a0&#8220;bitfield\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0&#8221;\u00a0&lt;&lt;\u00a0usedColors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;&lt;\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0&lt;&lt;\u00a0&#8220;number\u00a0\u00a0\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0&#8221;\u00a0&lt;&lt;\u00a0usedColors.count() \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;&lt;\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0&lt;&lt;\u00a0&#8220;bitfield\u00a0of\u00a0unused\u00a0colors:\u00a0&#8221;\u00a0&lt;&lt;\u00a0~usedColors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;&lt;\u00a0endl; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0any\u00a0color\u00a0is\u00a0used \u00a0\u00a0\u00a0\u00a0if\u00a0(usedColors.any())\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0loop\u00a0over\u00a0all\u00a0colors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for\u00a0(int\u00a0c\u00a0=\u00a00;\u00a0c\u00a0&lt;\u00a0numColors;\u00a0++c)\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0the\u00a0actual\u00a0color\u00a0is\u00a0used \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0(usedColors[(Color)c])\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/&#8230; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0} } \/*\u00a0 bitfield\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0001001 number\u00a0\u00a0\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a02 bitfield\u00a0of\u00a0unused\u00a0colors:\u00a0110110 \u00a0*\/<\/p>\n","protected":false},"author":130,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1420,1439,1417],"tags":[1431,1432],"class_list":["post-10064","post","type-post","status-publish","format-standard","hentry","category-c","category-c----","category-code-programming-samples--","tag-bitset","tag-enum","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":62225,"url":"http:\/\/bangla.sitestree.com\/?p=62225","url_meta":{"origin":10064,"position":0},"title":"Use bitset with enum together #Programming Code Examples #C++ #Bitset","author":"Author-Check- Article-or-Video","date":"May 15, 2021","format":false,"excerpt":"\u00a0 \u00a0 \/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book \u00a0*\u00a0\"The\u00a0C++\u00a0Standard\u00a0Library\u00a0-\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference\" \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999 \u00a0* \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999. \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies. \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0\"as\u00a0is\"\u00a0without\u00a0express\u00a0or\u00a0implied \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose. \u00a0*\/ #include\u00a0<bitset> #include\u00a0<iostream> using\u00a0namespace\u00a0std; int\u00a0main() { \u00a0\u00a0\u00a0\u00a0\/*\u00a0enumeration\u00a0type\u00a0for\u00a0the\u00a0bits \u00a0\u00a0\u00a0\u00a0\u00a0*\u00a0-\u00a0each\u00a0bit\u00a0represents\u00a0a\u00a0color \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0enum\u00a0Color\u00a0{\u00a0red,\u00a0yellow,\u00a0green,\u00a0blue,\u00a0white,\u00a0black,\u00a0\/\/..., \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0numColors\u00a0}; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0create\u00a0bitset\u00a0for\u00a0all\u00a0bits\/colors \u00a0\u00a0\u00a0\u00a0bitset<numColors>\u00a0usedColors; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0set\u00a0bits\u00a0for\u00a0two\u00a0colors \u00a0\u00a0\u00a0\u00a0usedColors.set(red); \u00a0\u00a0\u00a0\u00a0usedColors.set(blue); \u00a0\u00a0\u00a0\u00a0\/\/\u00a0print\u00a0some\u00a0bitset\u00a0data \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"bitfield\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0\"\u00a0<<\u00a0usedColors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"number\u00a0\u00a0\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0\"\u00a0<<\u00a0usedColors.count() \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"bitfield\u00a0of\u00a0unused\u00a0colors:\u00a0\"\u00a0<<\u00a0~usedColors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0any\u00a0color\u00a0is\u00a0used \u00a0\u00a0\u00a0\u00a0if\u00a0(usedColors.any())\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0loop\u00a0over\u00a0all\u00a0colors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for\u00a0(int\u00a0c\u00a0=\u00a00;\u00a0c\u00a0<\u00a0numColors;\u00a0++c)\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0the\u00a0actual\u00a0color\u00a0is\u00a0used \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0(usedColors[(Color)c])\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/... \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0} } \/*\u00a0 bitfield\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0001001 number\u00a0\u00a0\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a02 bitfield\u00a0of\u00a0unused\u00a0colors:\u00a0110110 \u00a0*\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10059,"url":"http:\/\/bangla.sitestree.com\/?p=10059","url_meta":{"origin":10064,"position":1},"title":"Transform binary representation into integral number using bitset","author":"","date":"July 27, 2015","format":false,"excerpt":"\/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book \u00a0*\u00a0\"The\u00a0C++\u00a0Standard\u00a0Library\u00a0-\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference\" \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999 \u00a0* \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999. \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies. \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0\"as\u00a0is\"\u00a0without\u00a0express\u00a0or\u00a0implied \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose. \u00a0*\/ #include\u00a0<bitset> #include\u00a0<iostream> #include\u00a0<string> #include\u00a0<limits> using\u00a0namespace\u00a0std; int\u00a0main() { \u00a0\u00a0\u00a0\u00a0\/*\u00a0print\u00a0some\u00a0numbers\u00a0in\u00a0binary\u00a0representation \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0short>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0long>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"10,000,000\u00a0with\u00a024\u00a0bits:\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<24>(1e7)\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0\/*\u00a0transform\u00a0binary\u00a0representation\u00a0into\u00a0integral\u00a0number \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"\\\"1000101011\\\"\u00a0as\u00a0number:\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<100>(string(\"1000101011\")).to_ulong()\u00a0<<\u00a0endl; } \u00a0\/*\u00a0 267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a00000000100001011 267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a000000000000000000000000100001011 10,000,000\u00a0with\u00a024\u00a0bits:\u00a0100110001001011010000000 1000101011\"\u00a0as\u00a0number:\u00a0\u00a0555 \u00a0*\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 \/\/ create a bitset that is 8 bits long bitset<8> bs;\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":62223,"url":"http:\/\/bangla.sitestree.com\/?p=62223","url_meta":{"origin":10064,"position":2},"title":"Transform binary representation into integral number using bitset #Programming Code Examples #C++ #Bitset","author":"Author-Check- Article-or-Video","date":"May 15, 2021","format":false,"excerpt":"\u00a0 \u00a0 \/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book \u00a0*\u00a0\"The\u00a0C++\u00a0Standard\u00a0Library\u00a0-\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference\" \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999 \u00a0* \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999. \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies. \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0\"as\u00a0is\"\u00a0without\u00a0express\u00a0or\u00a0implied \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose. \u00a0*\/ #include\u00a0<bitset> #include\u00a0<iostream> #include\u00a0<string> #include\u00a0<limits> using\u00a0namespace\u00a0std; int\u00a0main() { \u00a0\u00a0\u00a0\u00a0\/*\u00a0print\u00a0some\u00a0numbers\u00a0in\u00a0binary\u00a0representation \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0short>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0long>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"10,000,000\u00a0with\u00a024\u00a0bits:\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<24>(1e7)\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0\/*\u00a0transform\u00a0binary\u00a0representation\u00a0into\u00a0integral\u00a0number \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"\"1000101011\"\u00a0as\u00a0number:\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<100>(string(\"1000101011\")).to_ulong()\u00a0<<\u00a0endl; } \u00a0\/*\u00a0 267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a00000000100001011 267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a000000000000000000000000100001011 10,000,000\u00a0with\u00a024\u00a0bits:\u00a0100110001001011010000000 1000101011\"\u00a0as\u00a0number:\u00a0\u00a0555 \u00a0*\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 \/\/ create a bitset that is 8 bits long\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":68584,"url":"http:\/\/bangla.sitestree.com\/?p=68584","url_meta":{"origin":10064,"position":3},"title":"C++ Code Examples. Bitset, Vector, Valarray #77","author":"Author-Check- Article-or-Video","date":"August 5, 2021","format":false,"excerpt":"Bitset Transform binary representation into integral number using bitset Use bitset with enum together Vector Call member function for each element in vector Valarray Print minimum, maximum, and sum of the valarray valarray slice valarray with double value inside Std Algorithms Sort objects stored in deque Use sorting criterion in\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10070,"url":"http:\/\/bangla.sitestree.com\/?p=10070","url_meta":{"origin":10064,"position":4},"title":"Print minimum, maximum, and sum of the valarray","author":"","date":"July 27, 2015","format":false,"excerpt":"\/* The following code example is taken from the book * \"The C++ Standard Library - A Tutorial and Reference\" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10073,"url":"http:\/\/bangla.sitestree.com\/?p=10073","url_meta":{"origin":10064,"position":5},"title":"valarray slice","author":"","date":"July 27, 2015","format":false,"excerpt":"\/* The following code example is taken from the book * \"The C++ Standard Library - A Tutorial and Reference\" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided\u2026","rel":"","context":"In &quot;C++ \u0964 \u09b8\u09bf \u09aa\u09cd\u09b2\u09be\u09b8 \u09aa\u09cd\u09b2\u09be\u09b8&quot;","block_context":{"text":"C++ \u0964 \u09b8\u09bf \u09aa\u09cd\u09b2\u09be\u09b8 \u09aa\u09cd\u09b2\u09be\u09b8","link":"http:\/\/bangla.sitestree.com\/?cat=1439"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10064"}],"version-history":[{"count":2,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10064\/revisions"}],"predecessor-version":[{"id":10618,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10064\/revisions\/10618"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10064"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}