Friday, July 1, 2011

Add non-admin users to Developer Tools group on Mac

[Source: http://idtechnology.blogspot.com/2010/10/add-user-to-developer-tools-group.html]

To add a user to “Developer Tools” group:
dseditgroup -o edit -u {admin_user} -t user -a {user_name} _developer

Saturday, January 8, 2011

Bit Operation #9

Print out odd numbers from 1 to 100

void printOddNumber()
{
for (int i = 1; i <= 100; ++i)
{
if (i & 0x01)
cout << i << \n;
}
}

Bit Operation #8


100000
100000
------
011111

000000
000000
------
000000

100000
000000
------
000000

000100
000100
------
111011

100100
100100
------
011011

100100
000100
------
111011

010101
101010
------
000000

111111
111111
------
000000

// A function using bitwise operators for above results.
unsigned int f(unsigned int a, unsigned int b)
{
if (a & b)
{
return ~(a & b);
}
return 0;
}

Bit Operation #7

Find the largest possible integer

int largestInt()
{
return ~0;
}

Bit Operation #6

Extract a single bit from a character.

int extractBit(char byte, unsigned int pos)
{
assert(pos < 8);

return ((byte >> pos) & 1);
}


Extract a range of bits from a character.

char extractBitRange(char byte, unsigned int startPos, unsigned int offset)
{
assert((startPos + offset) < 8);
return (byte >> startPos) & ~(0xfe << offset);
}