FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Go Bitwise Flags and Bitmasks: Configuration Pattern Guide
How-ToTools

Go Bitwise Flags and Bitmasks: Configuration Pattern Guide

via Dev.toAsaduzzaman Pavel3h ago

I was adding my eighth boolean toggle to a config struct — EnableCompression , SkipValidation , LogQueries , and so on. Eight fields, eight if cfg.Field checks, eight more lines in my YAML. The boilerplate was starting to annoy me. Then I replaced them with this: type ConfigFlags int const ( EnableCompression ConfigFlags = 1 << iota // 1 (0001) SkipValidation // 2 (0010) LogQueries // 4 (0100) // next one is 8 (1000), then 16 (00010000)... ) cfg := EnableCompression | LogQueries if cfg & ( EnableCompression | LogQueries ) != 0 { // do stuff } One integer. One check for any combination. Bitwise operators — OR ( | ) to combine, AND ( & ) to check, XOR ( ^ ) to toggle — handle the logic. And iota generates the bit positions automatically. What bit flags look like Each bit in a byte represents a separate option. An RGB color example: const ( Red = 0 b00000001 // bit 0 Green = 0 b00000010 // bit 1 Blue = 0 b00000100 // bit 2 ) Visually, each bit position controls one color: bit: 7 6 5 4 3 2

Continue reading on Dev.to

Opens in a new tab

Read Full Article
0 views

Related Articles

How-To

Five years of building my game engine Taylor

Reddit Programming • 48m ago

Building My First Custom Mechanical Keyboard
How-To

Building My First Custom Mechanical Keyboard

Dev.to • 2h ago

The Adventures of Blink S5e6: On So Many Levels
How-To

The Adventures of Blink S5e6: On So Many Levels

Dev.to • 13h ago

Welcome Thread - v372
How-To

Welcome Thread - v372

Dev.to • 1d ago

ShadCN UI in 2026: the component library that changed how we build UIs
How-To

ShadCN UI in 2026: the component library that changed how we build UIs

Dev.to • 1d ago

Discover More Articles