Skip to main content
100%

DEC2BIN or HEX2BIN in Power Query M

✓ Published0🌍 Public
HHugoberry
Last edited Mar 15, 2017
Created on Mar 2, 2017

This example demonstrates a Power Query M function that converts a decimal number to its binary string representation, implementing the equivalent of Excel’s DEC2BIN and HEX2BIN operations. The function, `Number.DEC2BIN`, takes a numeric input and uses `List.Generate` to iteratively extract bits via `Number.BitwiseAnd` and `Number.BitwiseShiftRight`. Each iteration prepends the least significant bit to an accumulating string, while the loop continues until the remainder becomes zero. The code relies on M’s native `Number.ToText` for bit conversion and explicitly shows the bitwise arithmetic and list-generation logic, with no external libraries or data sources involved.

AI-generated description

Similar vizzes