# Problem with setting a bit

**URL:** <https://forum.kirupa.com/t/problem-with-setting-a-bit/330064>\
**Category:** Uncategorized\
**Created:** [November 25, 2012, 9:09am UTC](https://forum.kirupa.com/t/problem-with-setting-a-bit/330064 "2012-11-25T09:09:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reppinfreedom](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@reppinfreedom](https://forum.kirupa.com/u/reppinfreedom)\
**Post date:** [November 25, 2012, 9:09am UTC](https://forum.kirupa.com/t/problem-with-setting-a-bit/330064/1 "2012-11-25T09:09:16Z")

</div>

Something is wrong with this function.

```php

        public static function setBit(bitData:int, Bit:int, setTo:Boolean):int {
            var newBitData = bitData | (int(setTo) << Bit);
            return newBitData;
        }

var bitInt:int = 5;
            trace(bitInt);
           bitInt=bitFunctions.setBit(bitInt,0,false);//Or true
            trace(bitInt);

```

Running a trace on both sides for the number 5 shows no change… True or false.

This function seems to work properly in this code here…

```php

var bitInt:int=0;
                    if (tileType == 1 || tileType == 2) {
                        //Set bit 0 to true for walkable
                        bitInt=bitFunctions.setBit(bitInt,0,true);

                        if (tileType == 1) {
                            //Set bit 2 to true for buildable
                            bitInt=bitFunctions.setBit(bitInt,2,true);
                        }
                    }

                    pathMapVec[Row][Col]=bitInt;

```

The first function only seems to work when the bit isn’t set to begin with…
