# Using Bitmasks In Go

DevFeed: [Using Bitmasks In Go](<https://devfeed.tech/articles/using-bitmasks-in-go-22175.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2021/04/using-bitmasks-in-go.html>)

Published: 2021-04-09T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Server](<https://devfeed.tech/topics/server.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [learn](<https://devfeed.tech/tags/learn.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

A tutorial explains how bitmasks can store and process sets of keys efficiently in Go. It introduces binary representation, bitwise AND, OR, NOT, and shift operations, then applies them to representing three keys with three bits.

## Source excerpt

Introduction You write a server for a massively multiplayer online role-playing game (MMORPG). In the game, players collect keys and you want to design how to store the set of keys each player has. As an example, imagine the set of keys are copper, jade and crystal. You consider the following options for storing a player key sets: []string map[string]bool Both options will work, but did you consider a third option of using a bitmask? Using a bitmask will make storing and processing keys more efficient. Once you learn the mechanics, it will be readable and maintainable as well.