{"id":5082,"date":"2018-12-25T10:55:52","date_gmt":"2018-12-25T09:55:52","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=5082"},"modified":"2018-12-25T10:55:52","modified_gmt":"2018-12-25T09:55:52","slug":"bitmasks","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2018\/12\/25\/bitmasks\/","title":{"rendered":"Bitmasks"},"content":{"rendered":"<p><a href=\"https:\/\/blog.bitsrc.io\/bitmask-there-is-space-at-the-bottom-5a741d18c4e3\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"alignnone size-full\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/1200\/1%2A3Xp5tCpaASNw6wmHDirSyw.jpeg?w=910&#038;ssl=1\" alt=\"\" \/><\/a>\u00a0<em><a href=\"https:\/\/blog.bitsrc.io\/bitmask-there-is-space-at-the-bottom-5a741d18c4e3\">Bitmask: There Is Space at the Bottom \u2013 Bits and Pieces<\/a><\/em><\/p>\n<p>Interesting, but it would be more interesting if Eiffellized.<\/p>\n<p><!--more--><!--nextpage--><\/p>\n<blockquote>\n<div class=\"metabar u-clearfix js-metabar is-withBottomSection is-hiddenWhenMinimized is-transitioning is-maximized\">\n<div class=\"metabar-inner u-marginAuto u-maxWidth1032 js-metabarBottom\">\n<nav class=\"metabar-block metabar-block--below u-overflowHidden u-height44\" role=\"navigation\">\n<ul class=\"u-textAlignLeft u-noWrap u-overflowX u-paddingBottom100 u-sm-paddingLeft20 u-sm-paddingRight20 js-collectionNavItems\">\n<li class=\"metabar-navItem js-collectionNavItem  u-uiTextMedium u-fontSize14 u-inlineBlock u-textUppercase u-letterSpacing003 u-textColorNormal u-xs-paddingRight12 u-xs-marginRight0 u-paddingTop5 u-xs-paddingTop10\"><\/li>\n<li class=\"metabar-navItem js-collectionNavItem  u-uiTextMedium u-fontSize14 u-inlineBlock u-textUppercase u-letterSpacing003 u-textColorNormal u-xs-paddingRight12 u-xs-marginRight0 u-paddingTop5 u-xs-paddingTop10\"><a class=\"link link--darker link--darken u-accentColor--textDarken link--noUnderline u-baseColor--link js-navItemLink\" href=\"https:\/\/blog.bitsrc.io\/tagged\/javascript\">JAVASCRIPT<\/a><\/li>\n<li class=\"metabar-navItem js-collectionNavItem  u-uiTextMedium u-fontSize14 u-inlineBlock u-textUppercase u-letterSpacing003 u-textColorNormal u-xs-paddingRight12 u-xs-marginRight0 u-paddingTop5 u-xs-paddingTop10\"><a class=\"link link--darken u-accentColor--textDarken link--noUnderline u-baseColor--link js-navItemLink\" href=\"https:\/\/blog.bitsrc.io\/tagged\/react\">REACT<\/a><\/li>\n<li class=\"metabar-navItem js-collectionNavItem  u-uiTextMedium u-fontSize14 u-inlineBlock u-textUppercase u-letterSpacing003 u-textColorNormal u-xs-paddingRight12 u-xs-marginRight0 u-paddingTop5 u-xs-paddingTop10\"><a class=\"link link--darken u-accentColor--textDarken link--noUnderline u-baseColor--link js-navItemLink\" href=\"https:\/\/blog.bitsrc.io\/tagged\/web-development\">WEB DEV<\/a><\/li>\n<li class=\"metabar-navItem js-collectionNavItem  u-uiTextMedium u-fontSize14 u-inlineBlock u-textUppercase u-letterSpacing003 u-textColorNormal u-xs-paddingRight12 u-xs-marginRight0 u-paddingTop5 u-xs-paddingTop10\"><a class=\"link link--darken u-accentColor--textDarken link--noUnderline u-baseColor--link js-navItemLink\" href=\"https:\/\/blog.bitsrc.io\/tagged\/nodejs\">NODE<\/a><\/li>\n<li class=\"metabar-navItem js-collectionNavItem  u-paddingLeft0 is-external u-uiTextMedium u-fontSize14 u-inlineBlock u-textUppercase u-letterSpacing003 u-textColorNormal u-xs-paddingRight12 u-xs-marginRight0 u-paddingTop5 u-xs-paddingTop10\"><a class=\"link link--darkenOnHover u-accentColor--textDarken link--noUnderline u-baseColor--link js-navItemLink\" href=\"https:\/\/www.bitsrc.io\" target=\"_blank\" rel=\"nofollow noopener\">GET STARTED<\/a><\/li>\n<\/ul>\n<\/nav>\n<\/div>\n<\/div>\n<div class=\"metabar metabar--spacer js-metabarSpacer  u-height105 u-xs-height95\"><\/div>\n<article class=\" u-minHeight100vhOffset65 u-overflowHidden postArticle postArticle--full is-withAccentColors\" lang=\"en\">\n<header class=\"container u-maxWidth740\"><\/header>\n<div class=\"postArticle-content js-postField js-notesSource js-trackedPost\" data-post-id=\"5a741d18c4e3\" data-source=\"post_page\" data-collection-id=\"5c2fdf847f4a\" data-tracking-context=\"postPage\" data-scroll=\"native\">\n<section class=\"section section--body section--first\">\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h1 id=\"b86c\" class=\"graf graf--h3 graf--leading graf--title\">Bitmask: There Is Space at the\u00a0Bottom<\/h1>\n<div class=\"uiScale uiScale-ui--regular uiScale-caption--regular u-flexCenter u-marginVertical24 u-fontSize15 js-postMetaLockup\">\n<div class=\"u-flex0\"><a class=\"link u-baseColor--link avatar\" dir=\"auto\" href=\"https:\/\/blog.bitsrc.io\/@kurtwanger40?source=post_header_lockup\" data-action=\"show-user-card\" data-action-source=\"post_header_lockup\" data-action-value=\"a1ee806e09de\" data-action-type=\"hover\" data-user-id=\"a1ee806e09de\" data-collection-slug=\"bitsrc\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"avatar-image u-size50x50\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/fit\/c\/100\/100\/1%2AWSdkXxKtD8m54-1xp75cqQ.jpeg?w=910&#038;ssl=1\" alt=\"Go to the profile of Chidume Nnamdi \ud83d\udd25\ud83d\udcbb\ud83c\udfb5\ud83c\udfae\" \/><\/a><\/div>\n<div class=\"u-flex1 u-paddingLeft15 u-overflowHidden\">\n<div class=\"u-lineHeightTightest u-paddingBottom3\"><a class=\"ds-link ds-link--styleSubtle ui-captionStrong u-inlineBlock link link--darken link--darker\" dir=\"auto\" href=\"https:\/\/blog.bitsrc.io\/@kurtwanger40?source=post_header_lockup\" data-action=\"show-user-card\" data-action-source=\"post_header_lockup\" data-action-value=\"a1ee806e09de\" data-action-type=\"hover\" data-user-id=\"a1ee806e09de\" data-collection-slug=\"bitsrc\">Chidume Nnamdi \ud83d\udd25\ud83d\udcbb\ud83c\udfb5\ud83c\udfae<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/section>\n<\/div>\n<\/article>\n<div class=\"section-inner sectionLayout--insetColumn\">\n<div class=\"uiScale uiScale-ui--regular uiScale-caption--regular u-flexCenter u-marginVertical24 u-fontSize15 js-postMetaLockup\">\n<div class=\"u-flex1 u-paddingLeft15 u-overflowHidden\">\n<div class=\"ui-caption postMetaInline u-fontSize13 u-lineHeightBase js-testPostMetaInlineSupplemental\"><time datetime=\"2018-09-28T11:51:17.276Z\">Sep 28<\/time><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"section-inner sectionLayout--fullWidth\">\n<figure id=\"c560\" class=\"graf graf--figure graf--layoutFillWidth graf-after--h3\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*3Xp5tCpaASNw6wmHDirSyw.jpeg\" data-width=\"1920\" data-height=\"1357\" data-is-featured=\"true\" data-scroll=\"native\"><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<section class=\"section section--body section--first\">\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--fullWidth\">\n<figure id=\"c560\" class=\"graf graf--figure graf--layoutFillWidth graf-after--h3\" data-scroll=\"native\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*3Xp5tCpaASNw6wmHDirSyw.jpeg\" data-width=\"1920\" data-height=\"1357\" data-is-featured=\"true\" data-scroll=\"native\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/2000\/1%2A3Xp5tCpaASNw6wmHDirSyw.jpeg?w=910&#038;ssl=1\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/2000\/1*3Xp5tCpaASNw6wmHDirSyw.jpeg\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">Image from pixabay.com<\/figcaption><\/figure>\n<\/div>\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"0db4\" class=\"graf graf--p graf-after--figure\">There is so much space at the bottom. Deep down in <code class=\"\" data-line=\"\">Zeroes<\/code> and <code class=\"\" data-line=\"\">Ones<\/code>. At the quantum level. Enough space to contain a whole lot of information, we are talking about information <code class=\"\" data-line=\"\">&gt;<\/code> zillions bytes of data.<\/p>\n<p id=\"5141\" class=\"graf graf--p graf-after--p\">Those are words you come across in quantum physics. And they are very true.<\/p>\n<p id=\"3b75\" class=\"graf graf--p graf-after--p\">Calculations are performed in Computer\/CPU by pushing around 0s and 1s. We write programs in human-readable form and compilers transforms it into a string of bits that only the Computer\/CPU can understand.<\/p>\n<p id=\"17b2\" class=\"graf graf--p graf-after--p\">And in our programs, we write code to perform different operations using algorithms and algorithms are logic. And logic contains a lot of <code class=\"\" data-line=\"\">true<\/code> and <code class=\"\" data-line=\"\">false<\/code> variables. These eat up precious space in computers and affect the performance of our apps.<\/p>\n<p id=\"0181\" class=\"graf graf--p graf-after--p\">What if you could represent all your variables in bits? That you could use the bit states (0,1) of <strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">one binary number<\/em><\/strong> to represent the states(true, false) of your variables.<\/p>\n<p id=\"1b80\" class=\"graf graf--p graf-after--p\">This is done through the use of <strong class=\"markup--strong markup--p-strong\">bitmasks<\/strong>.<\/p>\n<blockquote id=\"7a29\" class=\"graf graf--pullquote graf-after--p\"><p>Bit masks enable the simultaneous storage and retrieval of multiple values using one variable.\u200a\u2014\u200a<a class=\"markup--anchor markup--pullquote-anchor\" href=\"https:\/\/abdulapopoola.com\/2016\/05\/30\/understanding-bit-masks\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/abdulapopoola.com\/2016\/05\/30\/understanding-bit-masks\/\">abdulapoopola<\/a><\/p><\/blockquote>\n<p id=\"7856\" class=\"graf graf--p graf-after--pullquote graf--trailing\">In this article, we will learn how to use bitmasks and its general applications. With this knowledge, you would save space(reduce your app code size) and make your app code much cleaner and faster on execution.<\/p>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"346a\" class=\"graf graf--p graf--leading\">Tip: reduce bundle-size and app weight using <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/bitsrc.io\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/bitsrc.io\"><strong class=\"markup--strong markup--p-strong\">Bit<\/strong><\/a><strong class=\"markup--strong markup--p-strong\">. <\/strong>Organize your component collection, choose and use the best ones, and share with your team. It\u2019s OSS.<\/p>\n<div id=\"0952\" class=\"graf graf--mixtapeEmbed graf-after--p\"><a class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https:\/\/bitsrc.io\" href=\"https:\/\/bitsrc.io\" data-href=\"https:\/\/bitsrc.io\"><strong class=\"markup--strong markup--mixtapeEmbed-strong\">Bit &#8211; Share and build with code components<\/strong><br \/>\n<em class=\"markup--em markup--mixtapeEmbed-em\">Bit helps you share, discover and use code components between projects and applications to build new features and\u2026<\/em>bitsrc.io<\/a><\/div>\n<h3 id=\"a12f\" class=\"graf graf--h3 graf-after--mixtapeEmbed\">Bitmasks<\/h3>\n<p id=\"b9fc\" class=\"graf graf--p graf-after--h3\">Bits in a number can be set either on or off in a single bitwise operation.<\/p>\n<p id=\"2196\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">What is a bitwise operation?<\/strong> It is an operation on numbers that operate at the bit level. This is accomplished using bitwise operators\u00a0: <code class=\"\" data-line=\"\">&amp;<\/code> (AND), <code class=\"\" data-line=\"\">|<\/code> (OR), <code class=\"\" data-line=\"\">&lt;&lt;<\/code> (SHIFT LEFT) and <code class=\"\" data-line=\"\">&gt;&gt;<\/code> (SHIFT RIGHT).<\/p>\n<p id=\"7df3\" class=\"graf graf--p graf-after--p\">Numbers are represented in <code class=\"\" data-line=\"\">0<\/code>s and <code class=\"\" data-line=\"\">1<\/code>s on the machine level. For example:<\/p>\n<pre id=\"60a5\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">Number | Binary\n---------------\n1      | 1\n2      | 10\n3      | 11\n4      | 100<\/code><\/pre>\n<p id=\"f247\" class=\"graf graf--p graf-after--pre\">We see the binary representation of numbers 1\u20134. If we apply any of the bitwise operators against any of them. their binary rep. will change thus changing the value of the number.<\/p>\n<p id=\"7b26\" class=\"graf graf--p graf-after--p\">Let\u2019s shift the bits of 2 to the left just once:<\/p>\n<pre id=\"be46\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">2 &lt;&lt; 1<\/code><\/pre>\n<pre id=\"8e11\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">10 (2 in binary)\n|\nv\n100 (4 in binary)<\/code><\/pre>\n<p id=\"0e2a\" class=\"graf graf--p graf-after--pre\">You see &lt;&lt; interfered with the bits and it resulted in another value (4).<\/p>\n<p id=\"9007\" class=\"graf graf--p graf-after--p\">Now, <strong class=\"markup--strong markup--p-strong\">what is bitmasking?<\/strong><\/p>\n<p id=\"4e66\" class=\"graf graf--p graf-after--p\">We saw that numbers are represented in 0 and 1. These bits can actually be used to represent a state in a set.<\/p>\n<p id=\"34d8\" class=\"graf graf--p graf-after--p\">Suppose, we have a collection of N elements. We can represent these elements in a sequence of N bits.<\/p>\n<p id=\"89ed\" class=\"graf graf--p graf-after--p\">Let\u2019s elaborate with an example:<\/p>\n<pre id=\"a2cc\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">[1,2,3,4,5,6,7,8]<\/code><\/pre>\n<p id=\"32a3\" class=\"graf graf--p graf-after--pre\">Above is our collection of elements (1 -&gt; 8). We can encode the collection of bits:<\/p>\n<pre id=\"b369\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">[1,1,0,1,1,0,1,0]<\/code><\/pre>\n<p id=\"833a\" class=\"graf graf--p graf-after--pre\"><em class=\"markup--em markup--p-em\">Credit: <\/em><a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/www.geeksforgeeks.org\/bitmasking-and-dynamic-programming-set-1-count-ways-to-assign-unique-cap-to-every-person\/\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/www.geeksforgeeks.org\/bitmasking-and-dynamic-programming-set-1-count-ways-to-assign-unique-cap-to-every-person\/\"><em class=\"markup--em markup--p-em\">Bitmasking and Dynamic Programming | Set 1 (Count ways to assign unique cap to every person)<\/em><\/a><\/p>\n<p id=\"cd96\" class=\"graf graf--p graf-after--p\">Each bit in an index represent the state of each element in the collection.<\/p>\n<ul class=\"postList\">\n<li id=\"fd4e\" class=\"graf graf--li graf-after--p\">0 -&gt; means the state is not set or disabled.<\/li>\n<li id=\"b900\" class=\"graf graf--li graf-after--li\">1 -&gt; indicates that the element at the index is set\/enabled.<\/li>\n<\/ul>\n<p id=\"da96\" class=\"graf graf--p graf-after--li\">Looking at our bits we can see that (1,2,4,5,7) are enabled\/set and (3,6,8) are disabled.<\/p>\n<p id=\"f2b1\" class=\"graf graf--p graf-after--p\">The collection of these bits is called a <strong class=\"markup--strong markup--p-strong\">bitmask<\/strong>.<\/p>\n<p id=\"3395\" class=\"graf graf--p graf-after--p\">If we remove the\u00a0<code class=\"\" data-line=\"\">,<\/code> in the bits you will see it will become this <code class=\"\" data-line=\"\">[11011010]<\/code> which is <code class=\"\" data-line=\"\">218<\/code> in the number system. So we could just use <code class=\"\" data-line=\"\">218<\/code> to represent <code class=\"\" data-line=\"\">[1,2,3,4,5,6,7,8]<\/code>. So much space at the bottom\u00a0:-).<\/p>\n<p id=\"5d4a\" class=\"graf graf--p graf-after--p\">Another example, we can rep. a human into bits. Actually, the characteristics of a human.<\/p>\n<p id=\"a149\" class=\"graf graf--p graf-after--p\">Using conventional programming, we could do this:<\/p>\n<pre id=\"b847\" class=\"graf graf--pre graf-after--p\">typedef struct human {\n    int hand,\n    int legs,\n    int head\n}\n human_t<\/pre>\n<pre id=\"7c67\" class=\"graf graf--pre graf-after--pre\">human_t h1\nh1.hand = true\nh1.legs = false\nh1.head = true<\/pre>\n<p id=\"6055\" class=\"graf graf--p graf-after--pre\">We can use the above struct to represent a human when we want to, let\u2019s say clone.<\/p>\n<p id=\"cf3b\" class=\"graf graf--p graf-after--p\">In the cloning machine, the system checks if the human to be cloned has everything set before proceeding.<\/p>\n<p id=\"410d\" class=\"graf graf--p graf-after--p\">The human struct can be represented in a string of bits:<\/p>\n<pre id=\"343b\" class=\"graf graf--pre graf-after--p\">typedef struct human {\n    int hand,\n    int legs,\n    int head\n}\n human_t<\/pre>\n<pre id=\"0707\" class=\"graf graf--pre graf-after--pre\">human_t h1\nh1.hand = 1\nh1.legs = 0\nh1.head = 1<\/pre>\n<p id=\"6b34\" class=\"graf graf--p graf-after--pre\">We can optimize further by rep the bits as a number.<\/p>\n<pre id=\"4b73\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">[1,0,1]<\/code><\/pre>\n<p id=\"2ceb\" class=\"graf graf--p graf-after--pre\">You see the above bits represent what was in the <code class=\"\" data-line=\"\">struct<\/code>. And removing the\u00a0<code class=\"\" data-line=\"\">,<\/code>s, it becomes <code class=\"\" data-line=\"\">101<\/code>, which is <code class=\"\" data-line=\"\">5<\/code> in the number system.<\/p>\n<p id=\"32ec\" class=\"graf graf--p graf-after--p\">We can remove the <code class=\"\" data-line=\"\">hand<\/code>, <code class=\"\" data-line=\"\">legs<\/code> and <code class=\"\" data-line=\"\">head<\/code> properties in the <code class=\"\" data-line=\"\">human<\/code> struct and represent the value of their bits as a single property, like this:<\/p>\n<pre id=\"3455\" class=\"graf graf--pre graf-after--p\">typedef struct human {\n    int value,\n}\n human_t<\/pre>\n<pre id=\"c762\" class=\"graf graf--pre graf-after--pre\">human_t h1\nh1.value = 5<\/pre>\n<p id=\"07a0\" class=\"graf graf--p graf-after--pre\">In the human struct, we have 3 states to represent. We can rep. all states in the range of 0 -&gt; 7 via combinations.<\/p>\n<pre id=\"2de1\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">hand | legs | head\n                         ------------------\nno limbs and no head     | 0 | 0 | 0\nno limbs, only head      | 0 | 0 | 1\nonly legs, no hands\/head | 0 | 1 | 0\nonly hand, no legs\/head  | 1 | 0 | 0\nno head, only legs\/hand  | 1 | 1 | 0\nno hand, only legs\/head  | 0 | 1 | 1\nno head, only hand\/legs  | 1 | 1 | 0\nall limbs and head       | 1 | 1 | 1<\/code><\/pre>\n<p id=\"787e\" class=\"graf graf--p graf-after--pre\">Another, suppose you have a blog and you have writers that can write and post articles on your blog. And there are permissions for who can post, edit or delete a post(s).<\/p>\n<pre id=\"ecec\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">owner  ----|- delete\nwriter --|-|- edit\n         |-|- post<\/code><\/pre>\n<p id=\"da22\" class=\"graf graf--p graf-after--pre\">We have 3 states: post, edit, post. Writes can only edit or post an article and Owners can post, edit or delete an article.<\/p>\n<pre id=\"9c43\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">| post | edit | delete\nOwners  | 1 | 1 | 1\nWriters | 1 | 1 | 0<\/code><\/pre>\n<p id=\"2300\" class=\"graf graf--p graf-after--pre\">You can employ writers with some permissions, maybe only post without edit or delete.<\/p>\n<pre id=\"c475\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">| post | edit | delete\nWriters | 1    | 0    | 0<\/code><\/pre>\n<p id=\"c5dc\" class=\"graf graf--p graf-after--pre\">In our program, we can have a struct for permissions:<\/p>\n<pre id=\"c833\" class=\"graf graf--pre graf-after--p\">struct owner {\n    \/\/...,\n    permission* p    \n}<\/pre>\n<pre id=\"b698\" class=\"graf graf--pre graf-after--pre\">struct writer {\n    \/\/...,\n    permission* p    \n}<\/pre>\n<pre id=\"9c58\" class=\"graf graf--pre graf-after--pre\">typedef struct permission {\n    bool post,\n    bool edit,\n    bool delete\n}\n permission_t<\/pre>\n<p id=\"5e47\" class=\"graf graf--p graf-after--pre\">we can reduce it to:<\/p>\n<pre id=\"3b53\" class=\"graf graf--pre graf-after--p\">struct owner {\n    \/\/...,\n    permission* p    \n}<\/pre>\n<pre id=\"9e97\" class=\"graf graf--pre graf-after--pre\">struct writer {\n    \/\/...,\n    permission* p    \n}<\/pre>\n<pre id=\"3ce3\" class=\"graf graf--pre graf-after--pre\">typedef struct permission {\n    int flag,\n}\n permission_t<\/pre>\n<p id=\"302e\" class=\"graf graf--p graf-after--pre\">:-), so much space.<\/p>\n<p id=\"f5a9\" class=\"graf graf--p graf-after--p\">The post, edit, delete properties in permission structure reduce to just flag.<\/p>\n<p id=\"687b\" class=\"graf graf--p graf-after--p\">The next sections <em class=\"markup--em markup--p-em\">Masking Bits\/Toggling\u00a0Bits <\/em>and<em class=\"markup--em markup--p-em\"> Querying Status of\u00a0Bit<\/em> were inspired by <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/en.wikipedia.org\/wiki\/Mask_%28computing%29#Common_bitmask_functions\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/en.wikipedia.org\/wiki\/Mask_%28computing%29#Common_bitmask_functions\">Wikipedia\u200a\u2014\u200aMask(computing)<\/a>.<\/p>\n<h3 id=\"9009\" class=\"graf graf--h3 graf-after--p\">Masking\/Toggling\u00a0Bits<\/h3>\n<p id=\"16af\" class=\"graf graf--p graf-after--h3\">Bits can be turned on (<code class=\"\" data-line=\"\">masked on<\/code>) or turned off (<code class=\"\" data-line=\"\">masked off<\/code>).<\/p>\n<p id=\"264c\" class=\"graf graf--p graf-after--p\">The <code class=\"\" data-line=\"\">|<\/code> operator is used to a bit on.<\/p>\n<p id=\"9df4\" class=\"graf graf--p graf-after--p\">Looking at an OR table<\/p>\n<pre id=\"1c70\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">00 =&gt; 0\n01 =&gt; 1\n10 =&gt; 1\n11 =&gt; 1<\/code><\/pre>\n<p id=\"9e37\" class=\"graf graf--p graf-after--pre\">Whenever a 1 is present, the result is 1. So we can deduce that in an OR operation this general principle is followed:<\/p>\n<pre id=\"cf38\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">N | 0 = N\nN | 1 = 1<\/code><\/pre>\n<p id=\"39c7\" class=\"graf graf--p graf-after--pre\">To turn a bit on it <code class=\"\" data-line=\"\">must<\/code> be <code class=\"\" data-line=\"\">OR<\/code>ed it with <code class=\"\" data-line=\"\">1<\/code>.<\/p>\n<p id=\"538d\" class=\"graf graf--p graf-after--p\">For example in our blog example, let\u2019s say a writer has the permissions:<\/p>\n<pre id=\"883c\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">ped\n110<\/code><\/pre>\n<p id=\"422d\" class=\"graf graf--p graf-after--pre\">The writer has only post and edit permission. If we want to give him a delete permission. The d bit has to be masked on, so it\u2019s ORed with 1:<\/p>\n<pre id=\"e7c5\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">ped\nOR  110\n    001\n    ---\n    111\n    ---<\/code><\/pre>\n<p id=\"836b\" class=\"graf graf--p graf-after--pre\">To turn a bit off, &amp; operator is used. Looking at the AND table:<\/p>\n<pre id=\"631f\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">00 =&gt; 0\n01 =&gt; 0\n10 =&gt; 0\n11 =&gt; 1<\/code><\/pre>\n<p id=\"81ab\" class=\"graf graf--p graf-after--pre\">We see that the general priniciple of the AND operation follows that:<\/p>\n<pre id=\"4714\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">N &amp; 1 =&gt; N\nN &amp; 0 =&gt; 0<\/code><\/pre>\n<p id=\"ece4\" class=\"graf graf--p graf-after--pre\">So, to turn off a bit, its <code class=\"\" data-line=\"\">AND<\/code>ed with 0, because the result is always <code class=\"\" data-line=\"\">0<\/code>.<\/p>\n<p id=\"5d03\" class=\"graf graf--p graf-after--p\">Let\u2019s say we have a writer with permissions:<\/p>\n<pre id=\"6870\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">ped\n111<\/code><\/pre>\n<p id=\"2e68\" class=\"graf graf--p graf-after--pre\">And we no longer want the writer to delete articles from our blog. To do that we AND his d permission with 0:<\/p>\n<pre id=\"5da7\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">ped\n&amp;   111\n    110\n    ---\n    110\n    ---<\/code><\/pre>\n<p id=\"6dc6\" class=\"graf graf--p graf-after--pre\">For a bit to remain unchanged, it is ANDed with its value. That\u2019s the reason we supplied <code class=\"\" data-line=\"\">11<\/code> to <code class=\"\" data-line=\"\">pe<\/code> permissions to leave them unchanged.<\/p>\n<h3 id=\"6113\" class=\"graf graf--h3 graf-after--p\">Querying Status of\u00a0Bit<\/h3>\n<p id=\"8a15\" class=\"graf graf--p graf-after--h3\">We can check the status of a bit by the <code class=\"\" data-line=\"\">AND<\/code>ing the bit by the value of bit you are checking against.<\/p>\n<p id=\"a3a2\" class=\"graf graf--p graf-after--p\">Let\u2019s say a writer has a writer\u2019s permissions <code class=\"\" data-line=\"\">110<\/code>. To check if he has the post permission, we AND the bitmask <code class=\"\" data-line=\"\">110<\/code> with the post flag <code class=\"\" data-line=\"\">100<\/code>. Let&#8217;s say we want to check if the post value of our writer is set <code class=\"\" data-line=\"\">1<\/code>:<\/p>\n<pre id=\"9919\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">ped\n    110\n&amp;   100\n    ---\n    100\n    ---<\/code><\/pre>\n<p id=\"15c9\" class=\"graf graf--p graf-after--pre\">The result is 100 which proves the post permission is set.<\/p>\n<p id=\"b790\" class=\"graf graf--p graf-after--p\">If the writer doesn\u2019t have post permission <code class=\"\" data-line=\"\">010<\/code>:<\/p>\n<pre id=\"c7e6\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">ped\n    010\n&amp;   100\n    ---\n    000\n    ---<\/code><\/pre>\n<p id=\"662c\" class=\"graf graf--p graf-after--pre\">The result proves the post bit is not set, he has no permission.<\/p>\n<h3 id=\"94bd\" class=\"graf graf--h3 graf-after--p\">Combining Bits<\/h3>\n<p id=\"17ad\" class=\"graf graf--p graf-after--h3\">Multiple states can be combined to set all states using the <code class=\"\" data-line=\"\">|<\/code> operator.<\/p>\n<p id=\"ebc3\" class=\"graf graf--p graf-after--p\">Using our blog example,<\/p>\n<pre id=\"fb30\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">ped\nd 001\ne 010\np 100<\/code><\/pre>\n<p id=\"29bf\" class=\"graf graf--p graf-after--pre\">delete has <code class=\"\" data-line=\"\">001<\/code> which is 1 in number system and also we can derive the value by shifting <code class=\"\" data-line=\"\">1<\/code> with a <code class=\"\" data-line=\"\">zero<\/code> to the left.<\/p>\n<p id=\"b6ff\" class=\"graf graf--p graf-after--p\">edit has <code class=\"\" data-line=\"\">010<\/code> which can be derived by shifting the binary value of <code class=\"\" data-line=\"\">1<\/code> to the left once <code class=\"\" data-line=\"\">1 &lt;&lt; 1<\/code>.<\/p>\n<p id=\"f573\" class=\"graf graf--p graf-after--p\">post has <code class=\"\" data-line=\"\">100<\/code>, which can also be derived by shifting the bits of <code class=\"\" data-line=\"\">1<\/code> twice to the left.<\/p>\n<pre id=\"d53f\" class=\"graf graf--pre graf-after--p\">enum PermissionFlags {\n    delete: 1 &lt;&lt; 0 \/\/ 001,\n    edit: 1 &lt;&lt; 1 \/\/ 010,\n    post: 1 &lt;&lt; 2 \/\/ 100\n}<\/pre>\n<p id=\"f530\" class=\"graf graf--p graf-after--pre\">Above is the rep. in C++. Let\u2019s say we have a writers structure like this:<\/p>\n<pre id=\"bcd0\" class=\"graf graf--pre graf-after--p\">struct writer {\n    int _permission\n}<\/pre>\n<p id=\"d222\" class=\"graf graf--p graf-after--pre\">It has a _permission property which stores the permissions of the writer.<\/p>\n<p id=\"468f\" class=\"graf graf--p graf-after--p\">We create a new writer like this:<\/p>\n<pre id=\"d7b5\" class=\"graf graf--pre graf-after--p\">writer* w = &lt;writer&gt;malloc(sizeof writer);<\/pre>\n<p id=\"ea1e\" class=\"graf graf--p graf-after--pre\">Next, we have to assign permissions to the newly created writer <code class=\"\" data-line=\"\">w<\/code>. Let&#8217;s say we want our writer to only post and edit but not delete.<\/p>\n<p id=\"4fe8\" class=\"graf graf--p graf-after--p\">To do this, we use | to combine the permissions from the PermissionFlags:<\/p>\n<pre id=\"598a\" class=\"graf graf--pre graf-after--p\">writer* w = &lt;writer&gt;malloc(sizeof writer);<\/pre>\n<pre id=\"38e3\" class=\"graf graf--pre graf-after--pre\">\/\/ writer `w` is given  post and edit access\nint* permission = PermissionFlags.post | PermissionFlags.edit;<\/pre>\n<pre id=\"5549\" class=\"graf graf--pre graf-after--pre\">w -&gt; _permission = permission;<\/pre>\n<p id=\"7057\" class=\"graf graf--p graf-after--pre\">The result of the | operation has both post and edit bits enabled.<\/p>\n<pre id=\"ffcc\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">d -001\ne -010\np -100<\/code><\/pre>\n<pre id=\"f22d\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">    010 (post)\n|   100 (edit)\n    ---\n    110\n    ---<\/code><\/pre>\n<p id=\"00cb\" class=\"graf graf--p graf-after--pre\">To set all the bits i.e to give the writer delete, post and edit permissions, we do this:<\/p>\n<pre id=\"0495\" class=\"graf graf--pre graf-after--p\">\/\/ ...\n\/\/ writer `w` is given delete, post and edit access\nint* permission = PermissionFlags.post | PermissionFlags.edit |PermissionFlags.delete ;\n\/\/ ...<\/pre>\n<p id=\"aaaa\" class=\"graf graf--p graf-after--pre\">Let\u2019s see the operation in binary:<\/p>\n<pre id=\"1e3c\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">001 (delete)\n|   010 (post)\n    100 (edit)\n    ---\n    111\n    ---<\/code><\/pre>\n<p id=\"3632\" class=\"graf graf--p graf-after--pre\">The result is <code class=\"\" data-line=\"\">111<\/code>, it has all the permissions bit set. We see that with | we can combine bits or flags or states.<\/p>\n<h3 id=\"1506\" class=\"graf graf--h3 graf-after--p\">Use Case: Blog\u00a0Example<\/h3>\n<p id=\"735f\" class=\"graf graf--p graf-after--h3\">Let\u2019s demonstrate what we have learned so far modeling our blog example.<\/p>\n<p id=\"f3b9\" class=\"graf graf--p graf-after--p\">Let\u2019s create three writers each with different permissions.<\/p>\n<pre id=\"a925\" class=\"graf graf--pre graf-after--p\">writer* w1 = &lt;writer&gt;malloc(sizeof writer);\nwriter* w2 = &lt;writer&gt;malloc(sizeof writer);\nwriter* w3 = &lt;writer&gt;malloc(sizeof writer);<\/pre>\n<p id=\"5c26\" class=\"graf graf--p graf-after--pre\">We will give w1 =&gt; post edit, w2 =&gt; edit delete, w3 =&gt; post edit delete<\/p>\n<pre id=\"a8cb\" class=\"graf graf--pre graf-after--p\">\/\/ ...\nw1 -&gt; _permission = PermissionFlags.post | PermissionFlags.edit;\nw2 -&gt; _permission = PermissionFlags.edit | PermissionFlags.delete;\nw3 -&gt; _permission = PermissionFlags.delete | PermissionFlags.post | PermissionFlags.edit;<\/pre>\n<p id=\"13e5\" class=\"graf graf--p graf-after--pre\">We create a function with a switch case to either post, edit delete an article.<\/p>\n<pre id=\"bc9d\" class=\"graf graf--pre graf-after--p\">void performAction(writer* _w, int type) {\n    int permission = w -&gt; _permission;\n    switch(type) {\n        case 1 \/* POST **\/: {<\/pre>\n<pre id=\"6146\" class=\"graf graf--pre graf-after--pre\">        }\n        case 2 \/* EDIT **\/: {<\/pre>\n<pre id=\"fc00\" class=\"graf graf--pre graf-after--pre\">        }\n        case 3 \/* DELETE **\/: {<\/pre>\n<pre id=\"5139\" class=\"graf graf--pre graf-after--pre\">        }\n    }\n}<\/pre>\n<p id=\"7cb3\" class=\"graf graf--p graf-after--pre\">Our <code class=\"\" data-line=\"\">performAction<\/code> function does nothing except match our action type against the switch cases and return.<\/p>\n<p id=\"4938\" class=\"graf graf--p graf-after--p\">In each switch case, we will add a logic to check the writer\u2019s permission before running the action. So in post case, the writer must have post permission before he can perform the action, and so on.<\/p>\n<pre id=\"a14a\" class=\"graf graf--pre graf-after--p\">void performAction(writer* _w, int type) {\n    int permission = _w -&gt; _permission;\n    switch(type) {\n        case 1 \/* POST **\/: {\n            if((permission &amp; PermissionFlags.post) === PermissionFlags.post){\n                cout &lt;&lt; 'blog posted!!';\n            }else {\n                cout &lt;&lt; 'Sorry, you don't have POST permission';\n            }\n        }\n        \/\/ ...\n    }\n}<\/pre>\n<p id=\"773a\" class=\"graf graf--p graf-after--pre\">We used the &amp; operator to check if the post bit is set on the writer.<\/p>\n<p id=\"d1ce\" class=\"graf graf--p graf-after--p\">If two states are combined using |. Each of the states can be retrieved from the combination by ANDing it with the desired state. If the result isn\u2019t the desired state then the state is not set.<\/p>\n<pre id=\"07f2\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">001 - p\n010 - d\n100 - e<\/code><\/pre>\n<pre id=\"efd1\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">_v = p | d = 011<\/code><\/pre>\n<pre id=\"8b73\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">001 |\n010\n---\n011\n---<\/code><\/pre>\n<pre id=\"701b\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">_v has p?\n011 &amp;\n001\n---\n001 yes\n---<\/code><\/pre>\n<pre id=\"fb80\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">_v has d?\n011 &amp;\n010\n---\n010 yes\n---<\/code><\/pre>\n<pre id=\"3bad\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">_v has e\n011 &amp;\n100\n---\n000 no\n---<\/code><\/pre>\n<p id=\"3d87\" class=\"graf graf--p graf-after--pre\">We can do the same for <code class=\"\" data-line=\"\">DELETE<\/code> and <code class=\"\" data-line=\"\">EDIT<\/code>:<\/p>\n<pre id=\"1897\" class=\"graf graf--pre graf-after--p\">void performAction(writer* _w, int type) {\n    int permission = _w -&gt; _permission;\n    switch(type) {\n        case 1 \/* POST **\/: {\n            if((permission &amp; PermissionFlags.post) === PermissionFlags.post){\n                cout &lt;&lt; 'blog posted!!';\n            }else {\n                cout &lt;&lt; 'Sorry, you don't have POST permission';\n            }\n        }\n        case 2 \/* EDIT **\/: {\n            if((permission &amp; PermissionFlags.edit) === PermissionFlags.edit){\n                cout &lt;&lt; 'blog edited!!';\n            }else {\n                cout &lt;&lt; 'Sorry, you don't have EDIT permission';\n            }\n        }\n        case 3 \/* DELETE **\/: {\n            if((permission &amp; PermissionFlags.delete) === PermissionFlags.delete){\n                cout &lt;&lt; 'blog deleted!!';\n            }else {\n                cout &lt;&lt; 'Sorry, you don't have DELETE permission';\n            }\n        }\n    }\n}<\/pre>\n<p id=\"f14f\" class=\"graf graf--p graf-after--pre\">Let\u2019s see it in action.<\/p>\n<pre id=\"4e33\" class=\"graf graf--pre graf-after--p\">const POST = 1;\nconst EDIT = 2;\nconst DELETE = 3;<\/pre>\n<pre id=\"c9c2\" class=\"graf graf--pre graf-after--pre\">\/\/...<\/pre>\n<pre id=\"2d31\" class=\"graf graf--pre graf-after--pre\">\/* remember w1 has only edit and post permissions\n*  writer w1 performs a POST action ie to post an article.\n**\/\nperformAction(w1, POST); \/\/ blog posted!!\n\/\/ The action is successful because it has post permission.\n\/\/ If he had tried to delete a blog, it will be denied\nperformAction(w1, DELETE); \/\/ Sorry, you don't have DELETE permission<\/pre>\n<p id=\"1bf6\" class=\"graf graf--p graf-after--pre\">You can try with writers <code class=\"\" data-line=\"\">w2<\/code> and <code class=\"\" data-line=\"\">w3<\/code>, and see them flex their permission powers.<\/p>\n<p id=\"cb02\" class=\"graf graf--p graf-after--p\">Let\u2019s add a function that can give a writer a particular permission.<\/p>\n<pre id=\"48c3\" class=\"graf graf--pre graf-after--p\">void givePermission(writer* w, int type) {\n    switch(type) {\n        case 1 \/* POST **\/: {\n            w -&gt; _permission |= PermissionFlags.post\n        }\n        case 2 \/* EDIT **\/: {\n            w -&gt; _permission |= PermissionFlags.edit\n        }\n        case 3 \/* DELETE **\/: {\n            w -&gt; _permission |= PermissionFlags.delete\n        }\n    }    \n}<\/pre>\n<p id=\"57f3\" class=\"graf graf--p graf-after--pre\">We learned earlier that | is used to turn on a bit. That\u2019s why we used it here. Each switch case ORs the writer\u2019s permission with the desired state, this sets the permission in the writer\u2019s _permission property.<\/p>\n<p id=\"63f5\" class=\"graf graf--p graf-after--p\">We know writer w1 has no delete permission, let\u2019s give it a delete power with this function:<\/p>\n<pre id=\"3946\" class=\"graf graf--pre graf-after--p\">\/\/...\nperformAction(w1, DELETE); \/\/ Sorry, you don't have DELETE permission\ngivePermission(w1, DELETE); \/* super power granted **\/\nperformAction(w1, DELETE); \/\/ blog deleted!!<\/pre>\n<p id=\"37d9\" class=\"graf graf--p graf-after--pre\">Also, we will need a function to remove a permission from a writer\u2019s permission.<\/p>\n<pre id=\"be9a\" class=\"graf graf--pre graf-after--p\">void removePermission(writer* w, int type) {\n    switch(type) {\n        case 1 \/* POST **\/: {\n            w -&gt; _permission &amp;= ~PermissionFlags.post\n        }\n        case 2 \/* EDIT **\/: {\n            w -&gt; _permission &amp;= ~PermissionFlags.edit\n        }\n        case 3 \/* DELETE **\/: {\n            w -&gt; _permission &amp;= ~PermissionFlags.delete\n        }\n    }\n}<\/pre>\n<p id=\"4cdc\" class=\"graf graf--p graf-after--pre\">There is a strange operator here <code class=\"\" data-line=\"\">~<\/code>. This operator flips the bits of a number to its inverse.<\/p>\n<p id=\"f0f5\" class=\"graf graf--p graf-after--p\">For example:<\/p>\n<pre id=\"a4b9\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">~ 1010 = 0101<\/code><\/pre>\n<p id=\"d5a2\" class=\"graf graf--p graf-after--pre\">To unset the bits of a state in a combination of states. The state to be unset is flipped to its inverse, the result is then ANDed with the combination.<\/p>\n<p id=\"0f47\" class=\"graf graf--p graf-after--p\">Looking at our code above, you see that\u2019s what we did.<\/p>\n<p id=\"a724\" class=\"graf graf--p graf-after--p\">flip the bits to its inverse and AND with the result.<\/p>\n<pre id=\"d702\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">p = 001\ne = 010\nd = 100<\/code><\/pre>\n<pre id=\"6e3e\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">_v = p | d = 101 (_v has p and d bits set)<\/code><\/pre>\n<pre id=\"3070\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">001 |\n100\n---\n101\n---<\/code><\/pre>\n<pre id=\"42a0\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">check _v has p<\/code><\/pre>\n<pre id=\"9c1c\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">101 &amp;\n001\n---\n001 yes, it has p\n---<\/code><\/pre>\n<pre id=\"2142\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">remove p\n        101 &amp;\n~(001)  110\n        ---\n   _v=  100\n        ---<\/code><\/pre>\n<pre id=\"38ce\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">_v now (100)<\/code><\/pre>\n<pre id=\"5202\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">check _v is set<\/code><\/pre>\n<pre id=\"6187\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">100 &amp;\n001\n---\n000 no p set\n---<\/code><\/pre>\n<p id=\"0101\" class=\"graf graf--p graf-after--pre\">No! writer w1 misused his DELETE super-power!. Let\u2019s strip him of his power.<\/p>\n<p id=\"79c1\" class=\"graf graf--p graf-after--p\">Here, let\u2019s see how this function removes DELETE permission from w1:<\/p>\n<pre id=\"d802\" class=\"graf graf--pre graf-after--p\">\/\/...\nperformAction(w1, DELETE); \/\/ blog deleted!!\n\/\/ oh gosh! he deleted another awesome article!!!<\/pre>\n<pre id=\"96dc\" class=\"graf graf--pre graf-after--pre\">removePermission(w1, DELETE); \/* super power removed, you are not worthy of this power **\/\nperformAction(w1, DELETE); \/\/ Sorry, you don't have DELETE permission<\/pre>\n<p id=\"c835\" class=\"graf graf--p graf-after--pre\">Here is the full source of our example:<\/p>\n<pre id=\"2810\" class=\"graf graf--pre graf-after--p\">enum PermissionFlags {\n    delete: 1 &lt;&lt; 0,\n    edit: 1 &lt;&lt; 1,\n    post: 1 &lt;&lt; 2\n}<\/pre>\n<pre id=\"fc54\" class=\"graf graf--pre graf-after--pre\">struct writer {\n    int _permission\n}<\/pre>\n<pre id=\"735b\" class=\"graf graf--pre graf-after--pre\">void performAction(writer* _w, int type) {\n    int permission = _w -&gt; _permission;\n    switch(type) {\n        case 1 \/* POST **\/: {\n            if((permission &amp; PermissionFlags.post) === PermissionFlags.post){\n                cout &lt;&lt; 'blog posted!!';\n            }else {\n                cout &lt;&lt; 'Sorry, you don't have POST permission';\n            }\n        }\n        case 2 \/* EDIT **\/: {\n            if((permission &amp; PermissionFlags.edit) === PermissionFlags.edit){\n                cout &lt;&lt; 'blog edited!!';\n            }else {\n                cout &lt;&lt; 'Sorry, you don't have EDIT permission';\n            }\n        }\n        case 3 \/* DELETE **\/: {\n            if((permission &amp; PermissionFlags.delete) === PermissionFlags.delete){\n                cout &lt;&lt; 'blog deleted!!';\n            }else {\n                cout &lt;&lt; 'Sorry, you don't have DELETE permission';\n            }\n        }\n    }\n}<\/pre>\n<pre id=\"681c\" class=\"graf graf--pre graf-after--pre\">void givePermission(writer* w, int type) {\n    switch(type) {\n        case 1 \/* POST **\/: {\n            w -&gt; _permission |= PermissionFlags.post\n        }\n        case 2 \/* EDIT **\/: {\n            w -&gt; _permission |= PermissionFlags.edit\n        }\n        case 3 \/* DELETE **\/: {\n            w -&gt; _permission |= PermissionFlags.delete\n        }\n    }    \n}<\/pre>\n<pre id=\"caae\" class=\"graf graf--pre graf-after--pre\">void removePermission(writer* w, int type) {\n    switch(type) {\n        case 1 \/* POST **\/: {\n            w -&gt; _permission &amp;= ~PermissionFlags.post\n        }\n        case 2 \/* EDIT **\/: {\n            w -&gt; _permission &amp;= ~PermissionFlags.edit\n        }\n        case 3 \/* DELETE **\/: {\n            w -&gt; _permission &amp;= ~PermissionFlags.delete\n        }\n    }\n}<\/pre>\n<pre id=\"0bb9\" class=\"graf graf--pre graf-after--pre\">int main() {\n    writer* w1 = malloc(sizeof writer);\n    writer* w2 = malloc(sizeof writer);\n    writer* w3 = malloc(sizeof writer);<\/pre>\n<pre id=\"f7ab\" class=\"graf graf--pre graf-after--pre\">    w1 -&gt; _permission = PermissionFlags.post | PermissionFlags.edit;\n    w2 -&gt; _permission = PermissionFlags.edit | PermissionFlags.delete;\n    w3 -&gt; _permission = PermissionFlags.delete | PermissionFlags.post | PermissionFlags.edit;<\/pre>\n<pre id=\"6697\" class=\"graf graf--pre graf-after--pre\">    \/\/ play around here<\/pre>\n<pre id=\"0c93\" class=\"graf graf--pre graf-after--pre\">    return 0;\n}<\/pre>\n<h3 id=\"1f40\" class=\"graf graf--h3 graf-after--pre\">Use Case:\u00a0Angular<\/h3>\n<p id=\"84e6\" class=\"graf graf--p graf-after--h3\">Angular made a very heavy use of bitmasks.<\/p>\n<ul class=\"postList\">\n<li id=\"c82c\" class=\"graf graf--li graf-after--p\">NodeFlags<\/li>\n<li id=\"ed8f\" class=\"graf graf--li graf-after--li\">ViewState<\/li>\n<li id=\"d314\" class=\"graf graf--li graf-after--li\">DepFlags<\/li>\n<li id=\"e491\" class=\"graf graf--li graf-after--li\">BindingFlags<\/li>\n<li id=\"3fe8\" class=\"graf graf--li graf-after--li\">ViewFlags<\/li>\n<\/ul>\n<p id=\"55de\" class=\"graf graf--p graf-after--li\">We will look into ViewState because it handles Change Detection which is very vital in any JS framework.<\/p>\n<pre id=\"edd2\" class=\"graf graf--pre graf-after--p\">\/\/ @angular\/core\/src\/view\/types.ts<\/pre>\n<pre id=\"4b64\" class=\"graf graf--pre graf-after--pre\">\/\/...<\/pre>\n<pre id=\"a49b\" class=\"graf graf--pre graf-after--pre\">\/**\n * Bitmask of states\n *\/\nexport const enum ViewState {\n  BeforeFirstCheck = 1 &lt;&lt; 0,\n  FirstCheck = 1 &lt;&lt; 1,\n  Attached = 1 &lt;&lt; 2,\n  ChecksEnabled = 1 &lt;&lt; 3,\n  IsProjectedView = 1 &lt;&lt; 4,\n  CheckProjectedView = 1 &lt;&lt; 5,\n  CheckProjectedViews = 1 &lt;&lt; 6,\n  Destroyed = 1 &lt;&lt; 7,<\/pre>\n<pre id=\"cb05\" class=\"graf graf--pre graf-after--pre\">  \/\/ InitState Uses 3 bits\n  InitState_Mask = 7 &lt;&lt; 8,\n  InitState_BeforeInit = 0 &lt;&lt; 8,\n  InitState_CallingOnInit = 1 &lt;&lt; 8,\n  InitState_CallingAfterContentInit = 2 &lt;&lt; 8,\n  InitState_CallingAfterViewInit = 3 &lt;&lt; 8,\n  InitState_AfterInit = 4 &lt;&lt; 8,<\/pre>\n<pre id=\"9a52\" class=\"graf graf--pre graf-after--pre\">  CatDetectChanges = Attached | ChecksEnabled,\n  CatInit = BeforeFirstCheck | CatDetectChanges | InitState_BeforeInit\n}<\/pre>\n<p id=\"6ccb\" class=\"graf graf--p graf-after--pre\">Each state has its own bit.<\/p>\n<pre id=\"a6b3\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">BeforeFirstCheck =  00000001,\n  FirstCheck =        00000010,\n  Attached =          00000100,\n  ChecksEnabled =     00001000,\n  IsProjectedView =   00010000,\n  CheckProjectedView  00100000,\n  CheckProjectedViews 01000000,\n  Destroyed =         10000000,<\/code><\/pre>\n<pre id=\"7a7d\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">\/\/ InitState uses 3 bits off to diff<\/code><\/pre>\n<pre id=\"09fa\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">  InitState_Mask =                    11100000000,\n  InitState_BeforeInit =              00000000,\n  InitState_CallingOnInit =           100000000,\n  InitState_CallingAfterContentInit = 1000000000,\n  InitState_CallingAfterViewInit =    1100000000,\n  InitState_AfterInit =               10000000000,<\/code><\/pre>\n<p id=\"a258\" class=\"graf graf--p graf-after--pre\">CatDetectChanges combines states Attached and ChecksEnabled<\/p>\n<pre id=\"bf1a\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">Attached      00000100 |\nChecksEnabled 00001000\n              --------\n              00001100\n              --------\nCatDetectChanges = 00001100<\/code><\/pre>\n<p id=\"23b4\" class=\"graf graf--p graf-after--pre\">See bits Attached and ChecksEnabled are set: 00001100<\/p>\n<p id=\"1365\" class=\"graf graf--p graf-after--p\">Also, CatInit combines states BeforeFirstCheck\u00a0,CatDetectChanges, InitState_BeforeInit<\/p>\n<pre id=\"dc57\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">BeforeFirstCheck     00000001 |\nCatDetectChanges     00001100\nInitState_BeforeInit 00000000\n                     --------\nCatInit =            00001101\n                     --------<\/code><\/pre>\n<p id=\"5ffb\" class=\"graf graf--p graf-after--pre\">You know CatDetectChanges has both Attached and ChecksEnabled flags set. So CatInit also has their flags set along with BeforeFirstCheck and InitState_BeforeInit.<\/p>\n<p id=\"5d8c\" class=\"graf graf--p graf-after--p\">An Angular app is made up of tree of views, each view represents a UI section of the app. Angular renders these views from the root of the tree up to the branches recursively.<\/p>\n<p id=\"3f94\" class=\"graf graf--p graf-after--p\">On initialization, Angular gives each view a <code class=\"\" data-line=\"\">ViewState<\/code> flag. This flag holds info on whether to render the view or not. And each view on creation is given the CatInit state.<\/p>\n<pre id=\"d830\" class=\"graf graf--pre graf-after--p\">function createView(...): ViewData {\n  \/\/ ...\n  const view: ViewData = {\n    \/\/...\n    state: ViewState.CatInit, root, renderer,\n    oldValues: new Array(def.bindingCount), disposables,\n    initIndex: -1\n  };\n  return view;\n}<\/pre>\n<p id=\"bfd9\" class=\"graf graf--p graf-after--pre\">When a change in the app\u2019s state is captured, a change detection cycle is triggered and UI re-render is initiated.<\/p>\n<p id=\"20f1\" class=\"graf graf--p graf-after--p\">During UI re-render of the views, the function checkAndUpdateView passes the current view to this function <code class=\"\" data-line=\"\">callViewAction<\/code>.<\/p>\n<pre id=\"385c\" class=\"graf graf--pre graf-after--p\">function callViewAction(view: ViewData, action: ViewAction) {\n  const viewState = view.state;\n  switch (action) {\n    \/\/ ...\n    case ViewAction.CheckAndUpdate:\n      if ((viewState &amp; ViewState.Destroyed) === 0) {\n        if ((viewState &amp; ViewState.CatDetectChanges) === ViewState.CatDetectChanges) {\n          checkAndUpdateView(view);\n        } else if (viewState &amp; ViewState.CheckProjectedViews) {\n          execProjectedViewsAction(view, ViewAction.CheckAndUpdateProjectedViews);\n        }\n      }\n      break;\n    \/\/ ...\n  }\n}<\/pre>\n<p id=\"91ad\" class=\"graf graf--p graf-after--pre\">This function checks whether view state is not destroyed. If not it checks if the CatDetectChanges flags in the view are set. If they are all set it renders the current view, if not the view is not rendered.<\/p>\n<p id=\"a035\" class=\"graf graf--p graf-after--p\">See, the use of AND &amp;, like we did in <code class=\"\" data-line=\"\">performAction<\/code> function in our blog example. If the CatDetectChanges flags are set on viewState, the AND operation will return the same flag.<\/p>\n<pre id=\"9be8\" class=\"graf graf--pre graf-after--p\"><code class=\"\" data-line=\"\">CatDetectChanges = 00001100\nviewState =        00001101 (views are created with CatInit flags)<\/code><\/pre>\n<pre id=\"6dd5\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">check CatDetectChanges is set in viewState<\/code><\/pre>\n<pre id=\"435e\" class=\"graf graf--pre graf-after--pre\"><code class=\"\" data-line=\"\">CatDetectChanges = 00001100 &amp;\nviewState =        00001101\n                   --------\n          result = 00001100\n                   --------\nthe result is the same as CatDetectChanges, so it is set and the view gets rendered.<\/code><\/pre>\n<p id=\"95ce\" class=\"graf graf--p graf-after--pre\">For some reasons, a view can be chosen not to be rendered. This is done by ViewRef_ class:<\/p>\n<pre id=\"164c\" class=\"graf graf--pre graf-after--p\">export class ViewRef_ implements EmbeddedViewRef&lt;any&gt;, InternalViewRef {\n  \/\/...\n  detach(): void { this._view.state &amp;= ~ViewState.Attached; }<\/pre>\n<pre id=\"6483\" class=\"graf graf--pre graf-after--pre\">  reattach(): void { this._view.state |= ViewState.Attached; }\n}<\/pre>\n<p id=\"1850\" class=\"graf graf--p graf-after--pre\">The method <code class=\"\" data-line=\"\">detach<\/code> removes a view from the tree of views, it doesn&#8217;t actually remove like cutting off but, disabling sorta thing.<\/p>\n<p id=\"b4d3\" class=\"graf graf--p graf-after--p\">It flips the bits of the <code class=\"\" data-line=\"\">Attached<\/code> state to its inverse and runs the AND operation against the view&#8217;s state (like we did in removePermission function in the blog example). The result is then, stored in the view&#8217;s state.<\/p>\n<blockquote id=\"c91d\" class=\"graf graf--pullquote graf-after--p\"><p><em class=\"markup--em markup--pullquote-em\">To remove a state from a combination of states, the bits of the state are inversed and ANDed against the combination of states. The result then becomes the combination of\u00a0states.<\/em><\/p><\/blockquote>\n<p id=\"1f9c\" class=\"graf graf--p graf-after--pullquote\">So, you see, the Attached was set. To detach, the Attached state has to be removed. That\u2019s why the Attached flag in the ViewState object was used.<\/p>\n<p id=\"c02e\" class=\"graf graf--p graf-after--p\">In reality, let\u2019s say we have a view:<\/p>\n<pre id=\"1f0d\" class=\"graf graf--pre graf-after--p\">const view = {\n    state: CatInit \/\/00001101\n}<\/pre>\n<p id=\"5163\" class=\"graf graf--p graf-after--pre\">To disable this view, ie to stop from being rendered. We do this:<\/p>\n<pre id=\"e295\" class=\"graf graf--pre graf-after--p\">\/\/...\nconst viewRef = new ViewRef_()\nviewRef.detach(view)<\/pre>\n<pre id=\"c48c\" class=\"graf graf--pre graf-after--pre\">what really happen:<\/pre>\n<pre id=\"f2da\" class=\"graf graf--pre graf-after--pre\">view.state =            00001101 \/\/CatInit\nAttached = 00000100 ~ = 11111011 &amp;\n                        --------\nview.state =            00001001\n                        --------<\/pre>\n<pre id=\"5e0a\" class=\"graf graf--pre graf-after--pre\">check Attached state is set.<\/pre>\n<pre id=\"615b\" class=\"graf graf--pre graf-after--pre\">view.state = 00001001 &amp;\nAttached =   00000100\n             --------\n             00000000 - Attached state not set\n             --------<\/pre>\n<p id=\"c947\" class=\"graf graf--p graf-after--pre\">Remember, CatDetectChanges sets Attached and ChecksEnabled 00001100.<\/p>\n<p id=\"ccc9\" class=\"graf graf--p graf-after--p\">Next, the reattach method sets the removed Attached flag. See it uses the OR <code class=\"\" data-line=\"\">|<\/code> operator. Just like we did in our <code class=\"\" data-line=\"\">givePermission<\/code> function in our blog example.<\/p>\n<pre id=\"a576\" class=\"graf graf--pre graf-after--p\">\/\/...\nconst viewRef = new ViewRef_()\nviewRef.detach(view)<\/pre>\n<pre id=\"d9c6\" class=\"graf graf--pre graf-after--pre\">what really happen:<\/pre>\n<pre id=\"eb76\" class=\"graf graf--pre graf-after--pre\">view.state =            00001101 \/\/CatInit\nAttached = 00000100 ~ = 11111011 &amp;\n                        --------\nview.state =            00001001\n                        --------<\/pre>\n<pre id=\"50f2\" class=\"graf graf--pre graf-after--pre\">check Attached state is set.<\/pre>\n<pre id=\"b577\" class=\"graf graf--pre graf-after--pre\">view.state = 00001001 &amp;\nAttached =   00000100\n             --------\n             00000000 - Attached state not set\n             --------<\/pre>\n<pre id=\"4268\" class=\"graf graf--pre graf-after--pre\">\/\/ To reattach `Attached` state\nviewRef.reattach(view)<\/pre>\n<pre id=\"8b93\" class=\"graf graf--pre graf-after--pre\">what happens:<\/pre>\n<pre id=\"d614\" class=\"graf graf--pre graf-after--pre\">view.state = 00001001 (the current state) |\nAttached =   00000100\n             --------\nview.state = 00001101\n             --------\ncheck Attached state is set.<\/pre>\n<pre id=\"5b51\" class=\"graf graf--pre graf-after--pre\">view.state = 00001101 &amp;\nAttached =   00000100\n             --------\n             00000100 - the Attached state is now set\n             --------<\/pre>\n<h3 id=\"8836\" class=\"graf graf--h3 graf-after--pre\">Conclusion<\/h3>\n<p id=\"3f50\" class=\"graf graf--p graf-after--h3\">We covered a lot here on bitmasks:<\/p>\n<ul class=\"postList\">\n<li id=\"8019\" class=\"graf graf--li graf-after--p\">&amp;, &lt;&lt;, &gt;&gt;, | operators.<\/li>\n<li id=\"53d0\" class=\"graf graf--li graf-after--li\">Turning bits on and off.<\/li>\n<li id=\"9c31\" class=\"graf graf--li graf-after--li\">Querying status of bits.<\/li>\n<li id=\"b966\" class=\"graf graf--li graf-after--li\">Combining bits.<\/li>\n<li id=\"bd5f\" class=\"graf graf--li graf-after--li\">Blog and Angular examples to demonstrate their usage.<\/li>\n<\/ul>\n<p id=\"a64b\" class=\"graf graf--p graf-after--li graf--trailing\">If you have any question regarding this or anything I should add, correct or remove, feel free to comment, email or DM me. It would be nice if you would play around with the blog example\u00a0\ud83d\ude42 Cheers!<\/p>\n<\/div>\n<\/div>\n<\/section>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">\u00a0Bitmask: There Is Space at the Bottom \u2013 Bits and Pieces Interesting, but it would be more interesting if Eiffellized.<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2018\/12\/25\/bitmasks\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[72],"tags":[],"class_list":["post-5082","post","type-post","status-publish","format-standard","hentry","category-documentations"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s6daft-bitmasks","jetpack-related-posts":[{"id":1229,"url":"https:\/\/monodes.com\/predaelli\/2016\/04\/01\/minimal-programming\/","url_meta":{"origin":5082,"position":0},"title":"Minimal Programming","author":"Paolo Redaelli","date":"2016-04-01","format":false,"excerpt":"Such an interesting site this Minimal Programming. Feels old school, written by proficient people! Therefore, minimal programming means minimal code: no code duplication maximal expressiveness: readable code that directly reflects the underlying task minimal overlap: every piece of information can be found in exactly one place maximal orthogonality: clear separation\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4917,"url":"https:\/\/monodes.com\/predaelli\/2018\/11\/14\/single-responsibility-principle\/","url_meta":{"origin":5082,"position":1},"title":"Single Responsibility Principle","author":"Paolo Redaelli","date":"2018-11-14","format":false,"excerpt":"Writing Flexible Code with the Single Responsibility Principle Mhmhmm... where have I heard of that SOLID principle? Ah, Eiffel! Severin Perez Writer | Developer | Information Specialist Sep 7 Writing Flexible Code with the Single Responsibility Principle SOLID Principles and Maintainable Code Photo by NASA on\u00a0Unsplash If you\u2019ve been around\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9368,"url":"https:\/\/monodes.com\/predaelli\/2022\/05\/09\/9368\/","url_meta":{"origin":5082,"position":2},"title":"https:\/\/github.com\/ulid\/spec That's interesting. I think\u2026","author":"Paolo Redaelli","date":"2022-05-09","format":false,"excerpt":"https:\/\/github.com\/ulid\/spec That's interesting. I think I shall make an Eiffel version one day","rel":"","context":"In &quot;Eiffel&quot;","block_context":{"text":"Eiffel","link":"https:\/\/monodes.com\/predaelli\/category\/eiffel\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9041,"url":"https:\/\/monodes.com\/predaelli\/2022\/01\/04\/is-the-macos-gui-development-scene-really-this-bad\/","url_meta":{"origin":5082,"position":3},"title":"Is the macOS GUI development scene really this bad?","author":"Paolo Redaelli","date":"2022-01-04","format":false,"excerpt":"Paul WalkerFollow on last summer asked Is the macOS GUI development scene really this bad? That's a question I'm interested in because while I've been using exclusively Linux since 1997 I strive to write portable programs. Most people are still \"shackled\" into proprietary operative systems. He enlist Swift, JavaScript, C#,\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":320,"url":"https:\/\/monodes.com\/predaelli\/2015\/06\/14\/go-flooding\/","url_meta":{"origin":5082,"position":4},"title":"Go flooding","author":"Paolo Redaelli","date":"2015-06-14","format":"status","excerpt":"https:\/\/github.com\/leanote\/leanote?files=1 Another interesting application written in Go. It seems that an interoperability between Go and Eiffel could be desirable...","rel":"","context":"In &quot;Eiffel&quot;","block_context":{"text":"Eiffel","link":"https:\/\/monodes.com\/predaelli\/category\/eiffel\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":847,"url":"https:\/\/monodes.com\/predaelli\/2015\/12\/10\/write-the-docs-helps-create-floss-software-documentation-video-slashdot\/","url_meta":{"origin":5082,"position":5},"title":"Write the Docs Helps Create FLOSS Software Documentation (Video) &#8211; Slashdot","author":"Paolo Redaelli","date":"2015-12-10","format":false,"excerpt":"http:\/\/m.slashdot.org\/story\/303819 Writing the docs is embedded in literate programming and should be the only natural way to do for a proper Eiffel programmer","rel":"","context":"In &quot;Eiffel&quot;","block_context":{"text":"Eiffel","link":"https:\/\/monodes.com\/predaelli\/category\/eiffel\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/5082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=5082"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/5082\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=5082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=5082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=5082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}