# Code definitions

Page 1 of 1

## 3 Replies - 587 Views - Last Post: 01 September 2010 - 08:10 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=188604&amp;s=728205f19e08da2e4e7d4fe7df5d3d8a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 irv_the_swerve

Reputation: 0
• Posts: 12
• Joined: 03-November 09

# Code definitions

Posted 01 September 2010 - 07:03 AM

Hi all,

Would anybody be able to explain what the following code parts mean (this is part of a wider program but I understand the rest of it)

```theArray[charPos] &= ~(1L << i);

```

I'm just wondering what '1L' means (I have also seen '~0L' too...something to do with the 'long' type? Does the tilde mean 'approx equal to' as in mathematical notation?).

Secondly I'm wondering what '<<' means...(the program utilises a bit-shift function if that helps).

Searched google and Java sources but can't find anything...any help would be great! Cheers.

Is This A Good Question/Topic? 0

## Replies To: Code definitions

### #2 japanir

• jaVanir

Reputation: 1012
• Posts: 3,025
• Joined: 20-August 09

## Re: Code definitions

Posted 01 September 2010 - 07:20 AM

Well the '~' is a bitwise operator is actually the logic operator NOT:
from sun's tutorial:

Quote

The unary bitwise complement operator "~" inverts a bit pattern; it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0". For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111".

'L' indicates a long constant.
in your code, the number '1' could be applied to an int variable as well. to indicate that it is a long variable, you use L, like: '1L'.

The signed left shift operator "<<" shifts a bit pattern to the left.
in your code, it shifts 1L i tims to the left.
for example, suppose the value is:
00000001 (represents 1 in 8 bits).
if you apply the << operator, like so:
1 << 1 (move one bit to the left) it would be:
00000010.

remember, that '<<' does not update the value in the number itself.
if you have something like this:
```int a = 1;
a << 2;
```

This code Wont change the value of a.
if you want to keep the value of a, you will have to assign it:
```a = a << 2;
```

anyways...
I'd really recommend taking a look at a bits tutorial:
http://www.javabegin...rators-tutorial

### #3 irv_the_swerve

Reputation: 0
• Posts: 12
• Joined: 03-November 09

## Re: Code definitions

Posted 01 September 2010 - 07:29 AM

Thanks very much for your reply I understand now...(it's my first time working with bit-operations lol). And thank you for the tutorial website, I've been looking for something like that

### #4 japanir

• jaVanir

Reputation: 1012
• Posts: 3,025
• Joined: 20-August 09

## Re: Code definitions

Posted 01 September 2010 - 08:10 AM

No problem