# Store, and modify data by bit position: Solidity Example **Published by:** [Hicss](https://paragraph.com/@freesuton/) **Published on:** 2023-02-06 **URL:** https://paragraph.com/@freesuton/store-and-modify-data-by-bit-position-solidity-example ## Content Input : n = 7, p = 3, b = 1 Output: 15 7 is 00000111 after setting bit at 3rd position it becomes 00001111. We first create a mask that has set bit only at given position using bit wise shift. mask = 1 << position Then to change value of bit to b, we first make it 0 using below operation value & ~mask After changing it 0, we change it to b by doing or of above expression with following (b << p) & mask, i.e., we return ((n & ~mask) | (b << p)) Input : n = 7, p = 3, b = 1 Output: 15 7 is 00000111 after setting bit at 3rd position it becomes 00001111. We first create a mask that has set bit only at given position using bit wise shift. mask = 1 << position Then to change value of bit to b, we first make it 0 using below operation value & ~mask After changing it 0, we change it to b by doing or of above expression with following (b << p) & mask, i.e., we return ((n & ~mask) | (b << p)) ## Publication Information - [Hicss](https://paragraph.com/@freesuton/): Publication homepage - [All Posts](https://paragraph.com/@freesuton/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@freesuton): Subscribe to updates - [Twitter](https://twitter.com/freesuton): Follow on Twitter