{
  "id": "bitmaps",
  "title": "Redis bitmaps",
  "url": "https://redis.io/docs/latest/develop/data-types/strings/bitmaps/",
  "summary": "Introduction to Redis bitmaps",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-05-26T09:29:27-05:00",
  "page_type": "content",
  "content_hash": "77d6b645f0042f195f05deee4c9599186290478395de047ec86c9be43ad5c8f5",
  "sections": [
    {
      "id": "bitmap-bitfield-command-summary",
      "title": "Bitmap/bitfield command summary",
      "role": "content",
      "text": "**7 commands in this group:**\n\n[View all bitmap commands](https://redis.io/commands/?group=bitmap)\n\n| Command | Summary | Complexity | Since |\n|---------|---------|------------|-------|\n| [BITCOUNT](https://redis.io/commands/bitcount/) | Counts the number of set bits (population counting) in a string. | O(N) | 2.6.0 |\n| [BITFIELD](https://redis.io/commands/bitfield/) | Performs arbitrary bitfield integer operations on strings. | O(1) for each subcommand specified | 3.2.0 |\n| [BITFIELD_RO](https://redis.io/commands/bitfield_ro/) | Performs arbitrary read-only bitfield integer operations on strings. | O(1) for each subcommand specified | 6.0.0 |\n| [BITOP](https://redis.io/commands/bitop/) | Performs bitwise operations on multiple strings, and stores the result. | O(N) | 2.6.0 |\n| [BITPOS](https://redis.io/commands/bitpos/) | Finds the first set (1) or clear (0) bit in a string. | O(N) | 2.8.7 |\n| [GETBIT](https://redis.io/commands/getbit/) | Returns a bit value by offset. | O(1) | 2.2.0 |\n| [SETBIT](https://redis.io/commands/setbit/) | Sets or clears the bit at offset of the string value. Creates the key if it doesn't exist. | O(1) | 2.2.0 |\n\n\n\nBitmaps are not an actual data type, but a set of bit-oriented operations\ndefined on the String type which is treated like a bit vector.\nSince strings are binary safe blobs and their maximum length is 512 MB,\nthey are suitable to set up to 2^32 different bits.\n\nYou can perform bitwise operations on one or more strings.\nSome examples of bitmap use cases include:\n\n* Efficient set representations for cases where the members of a set correspond to the integers 0-N.\n* Object permissions, where each bit represents a particular permission, similar to the way that file systems store permissions."
    },
    {
      "id": "example",
      "title": "Example",
      "role": "example",
      "text": "Suppose you have 1000 cyclists racing through the country-side, with sensors on their bikes labeled 0-999.\nYou want to quickly determine whether a given sensor has pinged a tracking server within the hour to check in on a rider. \n\nYou can represent this scenario using a bitmap whose key references the current hour.\n\n* Rider 123 pings the server on January 1, 2024 within the 00:00 hour. You can then confirm that rider 123 pinged the server. You can also check to see if rider 456 has pinged the server for that same hour.\n\nFoundational: Set and get individual bits using SETBIT and GETBIT to track binary states\n\n**Commands:** SETBIT, GETBIT\n\n**Complexity:**\n- SETBIT: O(1)\n- GETBIT: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]"
    },
    {
      "id": "bit-operations",
      "title": "Bit Operations",
      "role": "content",
      "text": "Bit operations are divided into two groups: constant-time single bit\noperations, like setting a bit to 1 or 0, or getting its value, and\noperations on groups of bits, for example counting the number of set\nbits in a given range of bits (e.g., population counting).\n\nOne of the biggest advantages of bitmaps is that they often provide\nextreme space savings when storing information. For example in a system\nwhere different users are represented by incremental user IDs, it is possible\nto remember a single bit information (for example, knowing whether\na user wants to receive a newsletter) of 4 billion users using just 512 MB of memory.\n\nThe [`SETBIT`](https://redis.io/docs/latest/commands/setbit) command takes as its first argument the bit number, and as its second\nargument the value to set the bit to, which is 1 or 0. The command\nautomatically enlarges the string if the addressed bit is outside the\ncurrent string length.\n\n[`GETBIT`](https://redis.io/docs/latest/commands/getbit) just returns the value of the bit at the specified index.\nOut of range bits (addressing a bit that is outside the length of the string\nstored into the target key) are always considered to be zero.\n\nThere are three commands operating on group of bits:\n\n1. [`BITOP`](https://redis.io/docs/latest/commands/bitop) performs bit-wise operations between different strings. The provided operators are `AND`, `OR`, `XOR`, `NOT`, `DIFF`, `DIFF1`, `ANDOR`, and `ONE`.\n2. [`BITCOUNT`](https://redis.io/docs/latest/commands/bitcount) performs population counting, reporting the number of bits set to 1.\n3. [`BITPOS`](https://redis.io/docs/latest/commands/bitpos) finds the first bit having the specified value of 0 or 1.\n\nBoth [`BITPOS`](https://redis.io/docs/latest/commands/bitpos) and [`BITCOUNT`](https://redis.io/docs/latest/commands/bitcount) are able to operate with byte ranges of the\nstring, instead of running for the whole length of the string. We can trivially see the number of bits that have been set in a bitmap.\n\nBit counting: Use BITCOUNT to count the number of set bits in a bitmap when you need to get population counts\n\n**Builds upon:** ping\n\n**Commands:** BITCOUNT\n\n**Complexity:**\n- BITCOUNT: O(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\nFor example imagine you want to know the longest streak of daily visits of\nyour web site users. You start counting days starting from zero, that is the\nday you made your web site public, and set a bit with [`SETBIT`](https://redis.io/docs/latest/commands/setbit) every time\nthe user visits the web site. As a bit index you simply take the current unix\ntime, subtract the initial offset, and divide by the number of seconds in a day\n(normally, 3600\\*24).\n\nThis way for each user you have a small string containing the visit\ninformation for each day. With [`BITCOUNT`](https://redis.io/docs/latest/commands/bitcount) it is possible to easily get\nthe number of days a given user visited the web site, while with\na few [`BITPOS`](https://redis.io/docs/latest/commands/bitpos) calls, or simply fetching and analyzing the bitmap client-side,\nit is possible to easily compute the longest streak."
    },
    {
      "id": "bitwise-operations",
      "title": "Bitwise operations",
      "role": "content",
      "text": "The [`BITOP`](https://redis.io/docs/latest/commands/bitop) command performs bitwise\noperations over two or more source keys, storing the result in a destination key.\n\nThe examples below show the available operations using three keys: `A` (with bit pattern\n`11011000`), `B` (`00011001`), and `C` (`01101100`).\n\n![images/dev/bitmap/BitopSetup.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopSetup.svg)\n\nNumbering the bits from left to right, starting at zero, the following `SETBIT` commands \nwill create these bitmaps:\n\nSetup for bitwise operations: Create multiple bitmaps using SETBIT to prepare for demonstrating bitwise operations\n\n**Difficulty:** Intermediate\n\n**Builds upon:** ping\n\n**Commands:** SETBIT, GET\n\n**Complexity:**\n- SETBIT: O(1)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\n#### `AND`\n\nSet a bit in the destination key to 1 only if it is set in all the source keys.\n\n![images/dev/bitmap/BitopAnd.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopAnd.svg)\n\nAND operation: Use BITOP AND to find bits set in all source bitmaps when you need to find common bits across multiple sets\n\n**Difficulty:** Intermediate\n\n**Builds upon:** bitop_setup\n\n**Commands:** BITOP, GET\n\n**Complexity:**\n- BITOP: O(N)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\n#### `OR`\nSet a bit in the destination key to 1 if it is set in at least one of the source keys.\n\n![images/dev/bitmap/BitopOr.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopOr.svg)\n\nOR operation: Use BITOP OR to find bits set in at least one source bitmap when you need to combine multiple sets\n\n**Difficulty:** Intermediate\n\n**Builds upon:** bitop_setup\n\n**Commands:** BITOP, GET\n\n**Complexity:**\n- BITOP: O(N)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\n#### `XOR`\n\nFor two source keys, set a bit in the destination key to 1 if the value of the bit is \ndifferent in the two keys. For three or more source keys, the result of XORing the first two \nkeys is then XORed with the next key, and so forth.\n\n![images/dev/bitmap/BitopXor.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopXor.svg)\n\nXOR operation: Use BITOP XOR to find bits that differ between bitmaps when you need to identify differences\n\n**Difficulty:** Intermediate\n\n**Builds upon:** bitop_setup\n\n**Commands:** BITOP, GET\n\n**Complexity:**\n- BITOP: O(N)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\n#### `NOT`\n\nSet a bit in the destination key to 1 if it is not set in the source key (this\nis the only unary operator).\n\n![images/dev/bitmap/BitopNot.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopNot.svg)\n\nNOT operation: Use BITOP NOT to invert all bits in a bitmap when you need to negate a set\n\n**Difficulty:** Intermediate\n\n**Builds upon:** bitop_setup\n\n**Commands:** BITOP, GET\n\n**Complexity:**\n- BITOP: O(N)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\n#### `DIFF`\n\nSet a bit in the destination key to 1 if it is set in the first source key, but not in any \nof the other source keys.\n\n![images/dev/bitmap/BitopDiff.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopDiff.svg)\n\nDIFF operation: Use BITOP DIFF to find bits set in the first bitmap but not in others when you need set difference\n\n**Difficulty:** Advanced\n\n**Builds upon:** bitop_setup\n\n**Commands:** BITOP, GET\n\n**Complexity:**\n- BITOP: O(N)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\n#### `DIFF1`\n\nSet a bit in the destination key to 1 if it is not set in the first source key, \nbut set in at least one of the other source keys.\n\n![images/dev/bitmap/BitopDiff1.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopDiff1.svg)\n\nDIFF1 operation: Use BITOP DIFF1 to find bits not in the first bitmap but in at least one other when you need inverse difference\n\n**Difficulty:** Advanced\n\n**Builds upon:** bitop_setup\n\n**Commands:** BITOP, GET\n\n**Complexity:**\n- BITOP: O(N)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\n#### `ANDOR`\n\nSet a bit in the destination key to 1 if it is set in the first source key and also in at least one of the other source keys.\n\n![images/dev/bitmap/BitopAndOr.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopAndOr.svg)\n\nANDOR operation: Use BITOP ANDOR to find bits in the first bitmap and at least one other when you need intersection with union\n\n**Difficulty:** Advanced\n\n**Builds upon:** bitop_setup\n\n**Commands:** BITOP, GET\n\n**Complexity:**\n- BITOP: O(N)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n\n\n#### `ONE`\n\nSet a bit in the destination key to 1 if it is set in exactly one of the source keys.\n\n![images/dev/bitmap/BitopOne.svg](https://redis.io/docs/latest/images/dev/bitmap/BitopOne.svg)\n\nONE operation: Use BITOP ONE to find bits set in exactly one bitmap when you need exclusive membership\n\n**Difficulty:** Advanced\n\n**Builds upon:** bitop_setup\n\n**Commands:** BITOP, GET\n\n**Complexity:**\n- BITOP: O(N)\n- GET: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]"
    },
    {
      "id": "split-bitmaps-into-multiple-keys",
      "title": "Split bitmaps into multiple keys",
      "role": "content",
      "text": "Bitmaps are trivial to split into multiple keys, for example for\nthe sake of sharding the data set and because in general it is better to\navoid working with huge keys. To split a bitmap across different keys\ninstead of setting all the bits into a key, a trivial strategy is just\nto store M bits per key and obtain the key name with `bit-number/M` and\nthe Nth bit to address inside the key with `bit-number MOD M`."
    },
    {
      "id": "performance",
      "title": "Performance",
      "role": "performance",
      "text": "[`SETBIT`](https://redis.io/docs/latest/commands/setbit) and [`GETBIT`](https://redis.io/docs/latest/commands/getbit) are O(1).\n[`BITOP`](https://redis.io/docs/latest/commands/bitop) is O(n), where _n_ is the length of the longest string in the comparison."
    },
    {
      "id": "learn-more",
      "title": "Learn more",
      "role": "related",
      "text": "* [Redis Bitmaps Explained](https://www.youtube.com/watch?v=oj8LdJQjhJo) teaches you how to use bitmaps for map exploration in an online game. \n* [Redis University's RU101](https://university.redis.com/courses/ru101/) covers Redis bitmaps in detail."
    }
  ],
  "examples": [
    {
      "id": "example-ex0",
      "language": "plaintext",
      "code": "> SETBIT pings:2024-01-01-00:00 123 1\n(integer) 0\n> GETBIT pings:2024-01-01-00:00 123\n1\n> GETBIT pings:2024-01-01-00:00 456\n0",
      "section_id": "example"
    },
    {
      "id": "example-ex1",
      "language": "csharp",
      "code": "bool res1 = db.StringSetBit(\"pings:2024-01-01-00:00\", 123, true);\n        Console.WriteLine(res1);    // >>> 0\n\n        bool res2 = db.StringGetBit(\"pings:2024-01-01-00:00\", 123);\n        Console.WriteLine(res2);    // >>> True\n\n        bool res3 = db.StringGetBit(\"pings:2024-01-01-00:00\", 456);\n        Console.WriteLine(res3);    // >>> False",
      "section_id": "example"
    },
    {
      "id": "example-ex2",
      "language": "go",
      "code": "res1, err := rdb.SetBit(ctx, \"pings:2024-01-01-00:00\", 123, 1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res1) // >>> 0\n\n\tres2, err := rdb.GetBit(ctx, \"pings:2024-01-01-00:00\", 123).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res2) // >>> 1\n\n\tres3, err := rdb.GetBit(ctx, \"pings:2024-01-01-00:00\", 456).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res3) // >>> 0",
      "section_id": "example"
    },
    {
      "id": "example-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> ping = async.setbit(\"pings:2024-01-01-00:00\", 123, 1).thenCompose(res1 -> {\n                System.out.println(res1); // >>> 0\n                return async.getbit(\"pings:2024-01-01-00:00\", 123);\n            }).thenCompose(res2 -> {\n                System.out.println(res2); // >>> 1\n                return async.getbit(\"pings:2024-01-01-00:00\", 456);\n            }).thenAccept(res3 -> {\n                System.out.println(res3); // >>> 0\n            }).toCompletableFuture();",
      "section_id": "example"
    },
    {
      "id": "example-ex4",
      "language": "java",
      "code": "Mono<Void> ping = reactive.setbit(\"pings:2024-01-01-00:00\", 123, 1).doOnNext(res1 -> {\n                System.out.println(res1); // >>> 0\n            }).flatMap(v -> reactive.getbit(\"pings:2024-01-01-00:00\", 123)).doOnNext(res2 -> {\n                System.out.println(res2); // >>> 1\n            }).flatMap(v -> reactive.getbit(\"pings:2024-01-01-00:00\", 456)).doOnNext(res3 -> {\n                System.out.println(res3); // >>> 0\n            }).then();",
      "section_id": "example"
    },
    {
      "id": "example-ex5",
      "language": "java",
      "code": "boolean res1 = jedis.setbit(\"pings:2024-01-01-00:00\", 123, true);\n        System.out.println(res1); // >>> false\n\n        boolean res2 = jedis.getbit(\"pings:2024-01-01-00:00\", 123);\n        System.out.println(res2); // >>> true\n\n        boolean res3 = jedis.getbit(\"pings:2024-01-01-00:00\", 456);\n        System.out.println(res3); // >>> false",
      "section_id": "example"
    },
    {
      "id": "example-ex6",
      "language": "javascript",
      "code": "const res1 = await client.setBit(\"pings:2024-01-01-00:00\", 123, 1)\nconsole.log(res1)  // >>> 0\n\nconst res2 = await client.getBit(\"pings:2024-01-01-00:00\", 123)\nconsole.log(res2)  // >>> 1\n\nconst res3 = await client.getBit(\"pings:2024-01-01-00:00\", 456)\nconsole.log(res3)  // >>> 0",
      "section_id": "example"
    },
    {
      "id": "example-ex7",
      "language": "php",
      "code": "$res1 = $r->setbit('pings:2024-01-01-00:00', 123, 1);\n        echo $res1 . PHP_EOL;\n        // >>> 0\n\n        $res2 = $r->getbit('pings:2024-01-01-00:00', 123);\n        echo $res2 . PHP_EOL;\n        // >>> 1\n\n        $res3 = $r->getbit('pings:2024-01-01-00:00', 456);\n        echo $res3 . PHP_EOL;\n        // >>> 0",
      "section_id": "example"
    },
    {
      "id": "example-ex8",
      "language": "python",
      "code": "res1 = r.setbit(\"pings:2024-01-01-00:00\", 123, 1)\nprint(res1)  # >>> 0\n\nres2 = r.getbit(\"pings:2024-01-01-00:00\", 123)\nprint(res2)  # >>> 1\n\nres3 = r.getbit(\"pings:2024-01-01-00:00\", 456)\nprint(res3)  # >>> 0",
      "section_id": "example"
    },
    {
      "id": "bit-operations-ex0",
      "language": "plaintext",
      "code": "> BITCOUNT pings:2024-01-01-00:00\n(integer) 1",
      "section_id": "bit-operations"
    },
    {
      "id": "bit-operations-ex1",
      "language": "csharp",
      "code": "bool res4 = db.StringSetBit(\"pings:2024-01-01-00:00\", 123, true);\n        long res5 = db.StringBitCount(\"pings:2024-01-01-00:00\");\n        Console.WriteLine(res5);    // >>> 1",
      "section_id": "bit-operations"
    },
    {
      "id": "bit-operations-ex2",
      "language": "go",
      "code": "res4, err := rdb.BitCount(ctx, \"pings:2024-01-01-00:00\",\n\t\t&redis.BitCount{\n\t\t\tStart: 0,\n\t\t\tEnd:   456,\n\t\t}).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res4) // >>> 1",
      "section_id": "bit-operations"
    },
    {
      "id": "bit-operations-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> bitcount = async.bitcount(\"pings:2024-01-01-00:00\").thenAccept(res4 -> {\n                System.out.println(res4); // >>> 1\n            }).toCompletableFuture();",
      "section_id": "bit-operations"
    },
    {
      "id": "bit-operations-ex4",
      "language": "java",
      "code": "Mono<Void> bitcount = reactive.bitcount(\"pings:2024-01-01-00:00\").doOnNext(res4 -> {\n                System.out.println(res4); // >>> 1\n            }).then();",
      "section_id": "bit-operations"
    },
    {
      "id": "bit-operations-ex5",
      "language": "java",
      "code": "long res4 = jedis.bitcount(\"pings:2024-01-01-00:00\");\n        System.out.println(res4); // >>> 1",
      "section_id": "bit-operations"
    },
    {
      "id": "bit-operations-ex6",
      "language": "javascript",
      "code": "await client.setBit(\"pings:2024-01-01-00:00\", 123, 1)\nconst res4 = await client.bitCount(\"pings:2024-01-01-00:00\")\nconsole.log(res4)  // >>> 1",
      "section_id": "bit-operations"
    },
    {
      "id": "bit-operations-ex7",
      "language": "php",
      "code": "// Ensure the bit is set\n        $r->setbit('pings:2024-01-01-00:00', 123, 1);\n        $res4 = $r->bitcount('pings:2024-01-01-00:00');\n        echo $res4 . PHP_EOL;\n        // >>> 1",
      "section_id": "bit-operations"
    },
    {
      "id": "bit-operations-ex8",
      "language": "python",
      "code": "r.setbit(\"pings:2024-01-01-00:00\", 123, 1)\nres4 = r.bitcount(\"pings:2024-01-01-00:00\")\nprint(res4)  # >>> 1",
      "section_id": "bit-operations"
    },
    {
      "id": "bitwise-operations-ex0",
      "language": "plaintext",
      "code": "> SETBIT A 0 1\n(integer) 0\n> SETBIT A 1 1\n(integer) 0\n> SETBIT A 3 1\n(integer) 0\n> SETBIT A 4 1\n(integer) 0\n> GET A\n\"\\xd8\"\n# Hex value: 0xd8 = 0b11011000\n\n> SETBIT B 3 1\n(integer) 0\n> SETBIT B 4 1\n(integer) 0\n> SETBIT B 7 1\n(integer) 0\n> GET B\n\"\\x19\"\n# Hex value: 0x19 = 0b00011001\n\n> SETBIT C 1 1\n(integer) 0\n> SETBIT C 2 1\n(integer) 0\n> SETBIT C 4 1\n(integer) 0\n> SETBIT C 5 1\n(integer) 0\n> GET C\n\"l\"\n# ASCII \"l\" = hex 0x6c = 0b01101100",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex1",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex2",
      "language": "go",
      "code": "rdb.SetBit(ctx, \"A\", 0, 1)\n\trdb.SetBit(ctx, \"A\", 1, 1)\n\trdb.SetBit(ctx, \"A\", 3, 1)\n\trdb.SetBit(ctx, \"A\", 4, 1)\n\tba, _ := rdb.Get(ctx, \"A\").Bytes()\n\tfmt.Printf(\"%08b\\n\", ba[0])\n\t// >>> 11011000\n\n\trdb.SetBit(ctx, \"B\", 3, 1)\n\trdb.SetBit(ctx, \"B\", 4, 1)\n\trdb.SetBit(ctx, \"B\", 7, 1)\n\tbb, _ := rdb.Get(ctx, \"B\").Bytes()\n\tfmt.Printf(\"%08b\\n\", bb[0])\n\t// >>> 00011001\n\n\trdb.SetBit(ctx, \"C\", 1, 1)\n\trdb.SetBit(ctx, \"C\", 2, 1)\n\trdb.SetBit(ctx, \"C\", 4, 1)\n\trdb.SetBit(ctx, \"C\", 5, 1)\n\tbc, _ := rdb.Get(ctx, \"C\").Bytes()\n\tfmt.Printf(\"%08b\\n\", bc[0])\n\t// >>> 01101100",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> setup = async.setbit(\"A\", 0, 1).thenCompose(v -> async.setbit(\"A\", 1, 1))\n                    .thenCompose(v -> async.setbit(\"A\", 3, 1)).thenCompose(v -> async.setbit(\"A\", 4, 1))\n                    .thenCompose(v -> async.setbit(\"B\", 3, 1)).thenCompose(v -> async.setbit(\"B\", 4, 1))\n                    .thenCompose(v -> async.setbit(\"B\", 7, 1)).thenCompose(v -> async.setbit(\"C\", 1, 1))\n                    .thenCompose(v -> async.setbit(\"C\", 2, 1)).thenCompose(v -> async.setbit(\"C\", 4, 1))\n                    .thenCompose(v -> async.setbit(\"C\", 5, 1)).thenCompose(v -> asyncBytes.get(\"A\".getBytes()))\n                    .thenApply(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bitsA = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bitsA); // >>> 11011000\n                        return bitsA;\n                    }).thenCompose(v -> asyncBytes.get(\"B\".getBytes())).thenApply(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bitsB = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bitsB); // >>> 00011001\n                        return bitsB;\n                    })\n                    // Print C\n                    .thenCompose(v -> asyncBytes.get(\"C\".getBytes())).thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bitsC = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bitsC); // >>> 01101100\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex4",
      "language": "java",
      "code": "Mono<Void> setup = reactive.setbit(\"A\", 0, 1).then(reactive.setbit(\"A\", 1, 1)).then(reactive.setbit(\"A\", 3, 1))\n                    .then(reactive.setbit(\"A\", 4, 1)).then(reactive.setbit(\"B\", 3, 1)).then(reactive.setbit(\"B\", 4, 1))\n                    .then(reactive.setbit(\"B\", 7, 1)).then(reactive.setbit(\"C\", 1, 1)).then(reactive.setbit(\"C\", 2, 1))\n                    .then(reactive.setbit(\"C\", 4, 1)).then(reactive.setbit(\"C\", 5, 1)).then(reactiveBytes.get(\"A\".getBytes()))\n                    .doOnNext(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bitsA = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bitsA); // >>> 11011000\n                    }).then(reactiveBytes.get(\"B\".getBytes())).doOnNext(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bitsB = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bitsB); // >>> 00011001\n                    }).then(reactiveBytes.get(\"C\".getBytes())).doOnNext(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bitsC = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bitsC); // >>> 01101100\n                    }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex5",
      "language": "java",
      "code": "jedis.setbit(\"A\", 0, true);\n        jedis.setbit(\"A\", 1, true);\n        jedis.setbit(\"A\", 3, true);\n        jedis.setbit(\"A\", 4, true);\n\n        byte[] res5 = jedis.get(\"A\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res5[0] & 0xFF)).replace(' ', '0'));\n        // >>> 11011000\n\n        jedis.setbit(\"B\", 3, true);\n        jedis.setbit(\"B\", 4, true);\n        jedis.setbit(\"B\", 7, true);\n\n        byte[] res6 = jedis.get(\"B\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res6[0] & 0xFF)).replace(' ', '0'));\n        // >>> 00011001\n\n        jedis.setbit(\"C\", 1, true);\n        jedis.setbit(\"C\", 2, true);\n        jedis.setbit(\"C\", 4, true);\n        jedis.setbit(\"C\", 5, true);\n\n        byte[] res7 = jedis.get(\"C\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res7[0] & 0xFF)).replace(' ', '0'));\n        // >>> 01101100",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex6",
      "language": "javascript",
      "code": "await client.setBit(\"A\", 0, 1)\nawait client.setBit(\"A\", 1, 1)\nawait client.setBit(\"A\", 3, 1)\nawait client.setBit(\"A\", 4, 1)\n\nconst res5 = await client.get(\"A\")\nconsole.log(res5.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 11011000\n\nawait client.setBit(\"B\", 3, 1)\nawait client.setBit(\"B\", 4, 1)\nawait client.setBit(\"B\", 7, 1)\n\nconst res6 = await client.get(\"B\")\nconsole.log(res6.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 00011001\n\nawait client.setBit(\"C\", 1, 1)\nawait client.setBit(\"C\", 2, 1)\nawait client.setBit(\"C\", 4, 1)\nawait client.setBit(\"C\", 5, 1)\n\nconst res7 = await client.get(\"C\")\nconsole.log(res7.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 01101100",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex7",
      "language": "php",
      "code": "$r->setbit('A', 0, 1);\n        $r->setbit('A', 1, 1);\n        $r->setbit('A', 3, 1);\n        $r->setbit('A', 4, 1);\n\n        $res5 = $r->get('A');\n        echo str_pad(decbin(ord($res5)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 11011000\n\n        $r->setbit('B', 3, 1);\n        $r->setbit('B', 4, 1);\n        $r->setbit('B', 7, 1);\n\n        $res6 = $r->get('B');\n        echo str_pad(decbin(ord($res6)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 00011001\n\n        $r->setbit('C', 1, 1);\n        $r->setbit('C', 2, 1);\n        $r->setbit('C', 4, 1);\n        $r->setbit('C', 5, 1);\n\n        $res7 = $r->get('C');\n        echo str_pad(decbin(ord($res7)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 01101100",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex8",
      "language": "python",
      "code": "r.setbit(\"A\", 0, 1)\nr.setbit(\"A\", 1, 1)\nr.setbit(\"A\", 3, 1)\nr.setbit(\"A\", 4, 1)\n\nres5 = r.get(\"A\")\nprint(\"{:08b}\".format(int.from_bytes(res5, \"big\")))\n# >>> 11011000\n\nr.setbit(\"B\", 3, 1)\nr.setbit(\"B\", 4, 1)\nr.setbit(\"B\", 7, 1)\n\nres6 = r.get(\"B\")\nprint(\"{:08b}\".format(int.from_bytes(res6, \"big\")))\n# >>> 00011001\n\nr.setbit(\"C\", 1, 1)\nr.setbit(\"C\", 2, 1)\nr.setbit(\"C\", 4, 1)\nr.setbit(\"C\", 5, 1)\n\nres7 = r.get(\"C\")\nprint(\"{:08b}\".format(int.from_bytes(res7, \"big\")))\n# >>> 01101100",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex9",
      "language": "plaintext",
      "code": "> BITOP AND R A B C\n(integer) 1\n> GET R\n\"\\b\"\n# ASCII \"\\b\" (backspace) = hex 0x08 = 0b00001000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex10",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex11",
      "language": "go",
      "code": "rdb.BitOpAnd(ctx, \"R\", \"A\", \"B\", \"C\")\n\tbr, _ := rdb.Get(ctx, \"R\").Bytes()\n\tfmt.Printf(\"%08b\\n\", br[0])\n\t// >>> 00001000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex12",
      "language": "java",
      "code": "CompletableFuture<Void> andOp = async.bitopAnd(\"R\", \"A\", \"B\", \"C\")\n                    .thenCompose(len -> asyncBytes.get(\"R\".getBytes())).thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 00001000\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex13",
      "language": "java",
      "code": "Mono<Void> andOp = reactive.bitopAnd(\"R\", \"A\", \"B\", \"C\").then(reactiveBytes.get(\"R\".getBytes())).doOnNext(res -> {\n                byte b = (res != null && res.length > 0) ? res[0] : 0;\n                String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                System.out.println(bits); // >>> 00001000\n            }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex14",
      "language": "java",
      "code": "jedis.bitop(BitOP.AND, \"R\", \"A\", \"B\", \"C\");\n        byte[] res8 = jedis.get(\"R\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res8[0] & 0xFF)).replace(' ', '0'));\n        // >>> 00001000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex15",
      "language": "javascript",
      "code": "await client.bitOp(\"AND\", \"R\", [\"A\", \"B\", \"C\"])\nconst res8 = await client.get(\"R\")\nconsole.log(res8.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 00001000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex16",
      "language": "php",
      "code": "$r->bitop('AND', 'R', 'A', 'B', 'C');\n        $res8 = $r->get('R');\n        echo str_pad(decbin(ord($res8)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 00001000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex17",
      "language": "python",
      "code": "r.bitop(\"AND\", \"R\", \"A\", \"B\", \"C\")\nres8 = r.get(\"R\")\nprint(\"{:08b}\".format(int.from_bytes(res8, \"big\")))\n# >>> 00001000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex18",
      "language": "plaintext",
      "code": "> BITOP OR R A B C\n(integer) 1\n> GET R\n\"\\xfd\"\n# Hex value: 0xfd = 0b11111101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex19",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex20",
      "language": "go",
      "code": "rdb.BitOpOr(ctx, \"R\", \"A\", \"B\", \"C\")\n\tbr, _ = rdb.Get(ctx, \"R\").Bytes()\n\tfmt.Printf(\"%08b\\n\", br[0])\n\t// >>> 11111101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex21",
      "language": "java",
      "code": "CompletableFuture<Void> orOp = async.bitopOr(\"R\", \"A\", \"B\", \"C\").thenCompose(len -> asyncBytes.get(\"R\".getBytes()))\n                    .thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 11111101\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex22",
      "language": "java",
      "code": "Mono<Void> orOp = reactive.bitopOr(\"R\", \"A\", \"B\", \"C\").then(reactiveBytes.get(\"R\".getBytes())).doOnNext(res -> {\n                byte b = (res != null && res.length > 0) ? res[0] : 0;\n                String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                System.out.println(bits); // >>> 11111101\n            }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex23",
      "language": "java",
      "code": "jedis.bitop(BitOP.OR, \"R\", \"A\", \"B\", \"C\");\n        byte[] res9 = jedis.get(\"R\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res9[0] & 0xFF)).replace(' ', '0'));\n        // >>> 11111101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex24",
      "language": "javascript",
      "code": "await client.bitOp(\"OR\", \"R\", [\"A\", \"B\", \"C\"])\nconst res9 = await client.get(\"R\")\nconsole.log(res9.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 11111101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex25",
      "language": "php",
      "code": "$r->bitop('OR', 'R', 'A', 'B', 'C');\n        $res9 = $r->get('R');\n        echo str_pad(decbin(ord($res9)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 11111101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex26",
      "language": "python",
      "code": "r.bitop(\"OR\", \"R\", \"A\", \"B\", \"C\")\nres9 = r.get(\"R\")\nprint(\"{:08b}\".format(int.from_bytes(res9, \"big\")))\n# >>> 11111101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex27",
      "language": "plaintext",
      "code": "> BITOP XOR R A B\n(integer) 1\n> GET R\n\"\\xc1\"\n# Hex value: 0xc1 = 0b11000001",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex28",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex29",
      "language": "go",
      "code": "rdb.BitOpXor(ctx, \"R\", \"A\", \"B\")\n\tbr, _ = rdb.Get(ctx, \"R\").Bytes()\n\tfmt.Printf(\"%08b\\n\", br[0])\n\t// >>> 11000001",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex30",
      "language": "java",
      "code": "CompletableFuture<Void> xorOp = async.bitopXor(\"R\", \"A\", \"B\").thenCompose(len -> asyncBytes.get(\"R\".getBytes()))\n                    .thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 11000001\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex31",
      "language": "java",
      "code": "Mono<Void> xorOp = reactive.bitopXor(\"R\", \"A\", \"B\").then(reactiveBytes.get(\"R\".getBytes())).doOnNext(res -> {\n                byte b = (res != null && res.length > 0) ? res[0] : 0;\n                String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                System.out.println(bits); // >>> 11000001\n            }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex32",
      "language": "java",
      "code": "jedis.bitop(BitOP.XOR, \"R\", \"A\", \"B\");\n        byte[] res10 = jedis.get(\"R\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res10[0] & 0xFF)).replace(' ', '0'));\n        // >>> 11000001",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex33",
      "language": "javascript",
      "code": "await client.bitOp(\"XOR\", \"R\", [\"A\", \"B\"]) // XOR uses two keys here\nconst res10 = await client.get(\"R\")\nconsole.log(res10.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 11000001",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex34",
      "language": "php",
      "code": "$r->bitop('XOR', 'R', 'A', 'B');\n        $res10 = $r->get('R');\n        echo str_pad(decbin(ord($res10)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 11000001",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex35",
      "language": "python",
      "code": "r.bitop(\"XOR\", \"R\", \"A\", \"B\")\nres10 = r.get(\"R\")\nprint(\"{:08b}\".format(int.from_bytes(res10, \"big\")))\n# >>> 11000001",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex36",
      "language": "plaintext",
      "code": "> BITOP NOT R A\n(integer) 1\n> GET R\n\"'\"\n# ASCII \"'\" (single quote) = hex 0x27 = 0b00100111",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex37",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex38",
      "language": "go",
      "code": "rdb.BitOpNot(ctx, \"R\", \"A\")\n\tbr, _ = rdb.Get(ctx, \"R\").Bytes()\n\tfmt.Printf(\"%08b\\n\", br[0])\n\t// >>> 00100111",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex39",
      "language": "java",
      "code": "CompletableFuture<Void> notOp = async.bitopNot(\"R\", \"A\").thenCompose(len -> asyncBytes.get(\"R\".getBytes()))\n                    .thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 00100111\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex40",
      "language": "java",
      "code": "Mono<Void> notOp = reactive.bitopNot(\"R\", \"A\").then(reactiveBytes.get(\"R\".getBytes())).doOnNext(res -> {\n                byte b = (res != null && res.length > 0) ? res[0] : 0;\n                String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                System.out.println(bits); // >>> 00100111\n            }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex41",
      "language": "java",
      "code": "jedis.bitop(BitOP.NOT, \"R\", \"A\");\n        byte[] res11 = jedis.get(\"R\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res11[0] & 0xFF)).replace(' ', '0'));\n        // >>> 00100111",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex42",
      "language": "javascript",
      "code": "await client.bitOp(\"NOT\", \"R\", \"A\")\nconst res11 = await client.get(\"R\")\nconsole.log(res11.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 00100111",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex43",
      "language": "php",
      "code": "$r->bitop('NOT', 'R', 'A');\n        $res11 = $r->get('R');\n        echo str_pad(decbin(ord($res11)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 00100111",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex44",
      "language": "python",
      "code": "r.bitop(\"NOT\", \"R\", \"A\")\nres11 = r.get(\"R\")\nprint(\"{:08b}\".format(int.from_bytes(res11, \"big\")))\n# >>> 00100111",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex45",
      "language": "plaintext",
      "code": "> BITOP DIFF R A B C\n(integer) 1\n> GET R\n\"\\x80\"\n# Hex value: 0x80 = 0b10000000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex46",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex47",
      "language": "go",
      "code": "rdb.BitOpDiff(ctx, \"R\", \"A\", \"B\", \"C\")\n\tbr, _ = rdb.Get(ctx, \"R\").Bytes()\n\tfmt.Printf(\"%08b\\n\", br[0])\n\t// >>> 10000000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex48",
      "language": "java",
      "code": "CompletableFuture<Void> diffOp = async.bitopDiff(\"R\", \"A\", \"B\", \"C\")\n                    .thenCompose(len -> asyncBytes.get(\"R\".getBytes())).thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 10000000\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex49",
      "language": "java",
      "code": "Mono<Void> diffOp = reactive.bitopDiff(\"R\", \"A\", \"B\", \"C\").then(reactiveBytes.get(\"R\".getBytes())).doOnNext(res -> {\n                byte b = (res != null && res.length > 0) ? res[0] : 0;\n                String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                System.out.println(bits); // >>> 10000000\n            }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex50",
      "language": "java",
      "code": "jedis.bitop(BitOP.DIFF, \"R\", \"A\", \"B\", \"C\");\n        byte[] res12 = jedis.get(\"R\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res12[0] & 0xFF)).replace(' ', '0'));\n        // >>> 10000000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex51",
      "language": "javascript",
      "code": "await client.bitOp(\"DIFF\", \"R\", [\"A\", \"B\", \"C\"])\nconst res12 = await client.get(\"R\")\nconsole.log(res12.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 10000000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex52",
      "language": "php",
      "code": "$r->bitop('DIFF', 'R', 'A', 'B', 'C');\n        $res12 = $r->get('R');\n        echo str_pad(decbin(ord($res12)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 10000000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex53",
      "language": "python",
      "code": "r.bitop(\"DIFF\", \"R\", \"A\", \"B\", \"C\")\nres12 = r.get(\"R\")\nprint(\"{:08b}\".format(int.from_bytes(res12, \"big\")))\n# >>> 10000000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex54",
      "language": "plaintext",
      "code": "> BITOP DIFF1 R A B C\n(integer) 1\n> GET R\n\"%\"\n# ASCII \"%\" (percent) = hex 0x25 = 0b00100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex55",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex56",
      "language": "go",
      "code": "rdb.BitOpDiff1(ctx, \"R\", \"A\", \"B\", \"C\")\n\tbr, _ = rdb.Get(ctx, \"R\").Bytes()\n\tfmt.Printf(\"%08b\\n\", br[0])\n\t// >>> 00100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex57",
      "language": "java",
      "code": "CompletableFuture<Void> diff1Op = async.bitopDiff1(\"R\", \"A\", \"B\", \"C\")\n                    .thenCompose(len -> asyncBytes.get(\"R\".getBytes())).thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 00100101\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex58",
      "language": "java",
      "code": "Mono<Void> diff1Op = reactive.bitopDiff1(\"R\", \"A\", \"B\", \"C\").then(reactiveBytes.get(\"R\".getBytes()))\n                    .doOnNext(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 00100101\n                    }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex59",
      "language": "java",
      "code": "jedis.bitop(BitOP.DIFF1, \"R\", \"A\", \"B\", \"C\");\n        byte[] res13 = jedis.get(\"R\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res13[0] & 0xFF)).replace(' ', '0'));\n        // >>> 00100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex60",
      "language": "javascript",
      "code": "await client.bitOp(\"DIFF1\", \"R\", [\"A\", \"B\", \"C\"])\nconst res13 = await client.get(\"R\")\nconsole.log(res13.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 00100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex61",
      "language": "php",
      "code": "$r->bitop('DIFF1', 'R', 'A', 'B', 'C');\n        $res13 = $r->get('R');\n        echo str_pad(decbin(ord($res13)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 00100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex62",
      "language": "python",
      "code": "r.bitop(\"DIFF1\", \"R\", \"A\", \"B\", \"C\")\nres13 = r.get(\"R\")\nprint(\"{:08b}\".format(int.from_bytes(res13, \"big\")))\n# >>> 00100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex63",
      "language": "plaintext",
      "code": "> BITOP ANDOR R A B C\n(integer) 1\n> GET R\n\"X\"\n# ASCII \"X\" = hex 0x58 = 0b01011000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex64",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex65",
      "language": "go",
      "code": "rdb.BitOpAndOr(ctx, \"R\", \"A\", \"B\", \"C\")\n\tbr, _ = rdb.Get(ctx, \"R\").Bytes()\n\tfmt.Printf(\"%08b\\n\", br[0])\n\t// >>> 01011000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex66",
      "language": "java",
      "code": "CompletableFuture<Void> andorOp = async.bitopAndor(\"R\", \"A\", \"B\", \"C\")\n                    .thenCompose(len -> asyncBytes.get(\"R\".getBytes())).thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 01011000\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex67",
      "language": "java",
      "code": "Mono<Void> andorOp = reactive.bitopAndor(\"R\", \"A\", \"B\", \"C\").then(reactiveBytes.get(\"R\".getBytes()))\n                    .doOnNext(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 01011000\n                    }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex68",
      "language": "java",
      "code": "jedis.bitop(BitOP.ANDOR, \"R\", \"A\", \"B\", \"C\");\n        byte[] res14 = jedis.get(\"R\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res14[0] & 0xFF)).replace(' ', '0'));\n        // >>> 01011000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex69",
      "language": "javascript",
      "code": "await client.bitOp(\"ANDOR\", \"R\", [\"A\", \"B\", \"C\"])\nconst res14 = await client.get(\"R\")\nconsole.log(res14.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 01011000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex70",
      "language": "php",
      "code": "$r->bitop('ANDOR', 'R', 'A', 'B', 'C');\n        $res14 = $r->get('R');\n        echo str_pad(decbin(ord($res14)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 01011000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex71",
      "language": "python",
      "code": "r.bitop(\"ANDOR\", \"R\", \"A\", \"B\", \"C\")\nres14 = r.get(\"R\")\nprint(\"{:08b}\".format(int.from_bytes(res14, \"big\")))\n# >>> 01011000",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex72",
      "language": "plaintext",
      "code": "> BITOP ONE R A B C\n(integer) 1\n> GET R\n\"\\xa5\"\n# Hex value: 0xa5 = 0b10100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex73",
      "language": "csharp",
      "code": "// Bitwise operations are not supported in NRedisStack.",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex74",
      "language": "go",
      "code": "rdb.BitOpOne(ctx, \"R\", \"A\", \"B\", \"C\")\n\tbr, _ = rdb.Get(ctx, \"R\").Bytes()\n\tfmt.Printf(\"%08b\\n\", br[0])\n\t// >>> 10100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex75",
      "language": "java",
      "code": "CompletableFuture<Void> oneOp = async.bitopOne(\"R\", \"A\", \"B\", \"C\")\n                    .thenCompose(len -> asyncBytes.get(\"R\".getBytes())).thenAccept(res -> {\n                        byte b = (res != null && res.length > 0) ? res[0] : 0;\n                        String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                        System.out.println(bits); // >>> 10100101\n                    }).toCompletableFuture();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex76",
      "language": "java",
      "code": "Mono<Void> oneOp = reactive.bitopOne(\"R\", \"A\", \"B\", \"C\").then(reactiveBytes.get(\"R\".getBytes())).doOnNext(res -> {\n                byte b = (res != null && res.length > 0) ? res[0] : 0;\n                String bits = String.format(\"%8s\", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');\n                System.out.println(bits); // >>> 10100101\n            }).then();",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex77",
      "language": "java",
      "code": "jedis.bitop(BitOP.ONE, \"R\", \"A\", \"B\", \"C\");\n        byte[] res15 = jedis.get(\"R\".getBytes());\n        System.out.println(String.format(\"%8s\", Integer.toBinaryString(res15[0] & 0xFF)).replace(' ', '0'));\n        // >>> 10100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex78",
      "language": "javascript",
      "code": "await client.bitOp(\"ONE\", \"R\", [\"A\", \"B\", \"C\"])\nconst res15 = await client.get(\"R\")\nconsole.log(res15.readUInt8(0).toString(2).padStart(8, '0'))\n// >>> 10100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex79",
      "language": "php",
      "code": "$r->bitop('ONE', 'R', 'A', 'B', 'C');\n        $res15 = $r->get('R');\n        echo str_pad(decbin(ord($res15)), 8, '0', STR_PAD_LEFT) . PHP_EOL;\n        // >>> 10100101",
      "section_id": "bitwise-operations"
    },
    {
      "id": "bitwise-operations-ex80",
      "language": "python",
      "code": "r.bitop(\"ONE\", \"R\", \"A\", \"B\", \"C\")\nres15 = r.get(\"R\")\nprint(\"{:08b}\".format(int.from_bytes(res15, \"big\")))\n# >>> 10100101",
      "section_id": "bitwise-operations"
    }
  ]
}
