Flip binary bits(binary)

Code examples

0
0

var flipbits = function (v, digits) {
        return ~v & (Math.pow(2, digits) - 1);
    }
    console.log(flipbits(5, 3)); // outputs 2
    console.log(flipbits(2, 3)); // outputs 5
 Run code snippetHide results

Similar pages

Similar pages with examples

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................