Question

I am running Sharepoint 2007 farm and am trying to calculate user permissions. I have read This post about the particular metadata field where I am getting my mask from. And I have been looking at The following guide in order to see what masks I need to compare to.

Here is my delima, whenever I run the following code in a IE javascript console I get back 0:

((0x4000000000000000).toString(16) & (0x400001F07FFF1BFF).toString(16))

Now I know this is incorrect because the respective binary values are:

100000000000000000000000000000000000000000000000000000000000000
100000000000000000000011111000001111111111111110001101111111111

Which should equal

100000000000000000000000000000000000000000000000000000000000000

I have also put this into my windows calculator just to make sure I wasn't crazy (and to get those super long binary numbers).

NOTE As I got to this line I realized that my browser is 32bit (which is a requirement for the site I am using this on) and this is a 64 bit number!

How can I (preferably in one line) calculate the bitwise AND of a two 64bit numbers using a 32bit browser?

I do know that I could convert the number into a binary String and utilize a loop to check each bit but is there a simpler method?

EDIT - Solution Utilizing the information from This Post and the answer below I came up with the following solution:

     var canEdit = false;
var canEditMask = [0x00000000,0x00000004];
var canApprove = false;
var canApproveMask = [0x00000000,0x00000010];
var canRead = false;
var canReadMask = [0x00000000,0x00000001];
var canDesign = false;
var canDesignMask = [0x00000000,0x00000800];
var mask = [originalmask.substring(0,10).toString(16),
                  ("0x"+itemperms.substring(9)).toString(16)];
canEdit = (mask[0] & canEditMask[0]) >0 || (mask[1] & canEditMask[1]) >0;
canRead = (mask[0] & canReadMask[0]) >0 || (mask[1] & canReadMask[1]) >0;
canDesign = (mask[0] & canDesignMask[0]) >0 || (mask[1] & canDesignMask[1]) >0;
canApprove = (mask[0] & canApproveMask[0]) >0 || (mask[1] & canApproveMask[1]) >0;
Was it helpful?

Solution 2

It's not really your browser that's the issue but the language specification. In short.. the logical bitwise operators &, | etc all treat their operands as 32-bit integers:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators

In order to do 64-bit wide operation you're going to have to rely on a library or write your own function.

OTHER TIPS

I hit the same problem this evening, so I wrote the following to allow bitwise AND and OR of values above 2^32:

    function bitand(val, bit) {
        if (bit > 0xFFFFFFF || val > 0xFFFFFFF) {
            var low = val & 0xFFFFFFF;
            var lowbit = bit & 0xFFFFFFF;
            val /= 0x10000000;
            bit /= 0x10000000;
            return (val & bit) * 0x10000000 + (low & lowbit);
        }
        return (val & bit);
    }

    function bitor(val, bit) {
        if (bit > 0xFFFFFFF || val > 0xFFFFFFF) {
            var low = val & 0xFFFFFFF;
            var lowbit = bit & 0xFFFFFFF;
            val /= 0x10000000;
            bit /= 0x10000000;
            return (val | bit) * 0x10000000 + (low | lowbit);
        }
        return (val | bit);
    }

Cheers, Jason

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top