Code Explainers

Code explainers tagged #bitwise

typescript
type RGB = { r: number; g: number; b: number };
 
function parseHex(hex: string): RGB {
  const normalized = hex.replace(/^#/, "").trim();

Lightening and darkening hex colors in TypeScript

bitwise color-manipulation parsing
Intermediate 9 steps
javascript
function parseHexColor(hex) {
  const cleaned = hex.trim().replace(/^#/, '');
 
  const expand = (short) =>

Parsing hex colors into RGBA channels

parsing bitwise regex
Intermediate 7 steps
javascript
function hexToRgb(hex) {
  const normalized = hex.replace(/^#/, '');
  const full = normalized.length === 3
    ? normalized.split('').map((c) => c + c).join('')

Building a two-way color picker in JS

bitwise dom-events data-conversion
Intermediate 9 steps