Developing Matt

My Technical Journal

var vBit=1

leave a comment »

Coworker Wade wrote:

What is this doing: var vBit=1<<(pDate.getUTCDate()-1);

I didn’t know so I wrote Boss Mark:

Hey Mark, what’s this do? Tell me so i can write back to wade and act like I know.

Brilliant Boss Mark wrote:

<< – left shift operator

It is a bitwise operation. It is in the from a << b where b is the number of bits to shift a to the left. So if a = 1 and b=4 then it would look like this: 00000001

After the operation it would be 00010000 or 16
In javascript getutcdate would return the day of the month. So looking at this as a whole I would say it returns the day of the month of the variable pdate then subtracts 1. Then vbit would equal that shifted over x number of bits. I would guess they are using a bitmask to represent everyday of the month. It is probably a 32 bit mask and they use this to decide if it is going to select or highlight the day or not.

And so of course I had to write coworker Wade back:

hey wade. that’s an easy one! let me enlighten you with my knowledge. I asked mark and 100 other experienced programmers and they didn’t know the answer. but i did! Here’s the answer…..(enter text from mark)


Written by matt

November 2, 2007 at 9:41 am

Posted in javascript

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: