g | x | w | all
Bytes Lang Time Link
004Uiua241115T173050Znyxbird
029AWK241115T172705Zxrs
006Japt241115T115510ZShaggy
087C110204T115349Zfat0ss
036SmileBASIC170216T214832Z12Me21
009J160609T002334ZLeaky Nu
nan110204T100642ZDaniel
029Racket scheme160609T131828ZSimon Ze
016Golfscript110207T052307Zgnibbler
031Perl110206T095812ZJ B

Uiua, 4 bytes

⍜⋯˜↙

Try it!

⍜ under converting n into ⋯ bits, ↙ take the first (least significant) m bits.

AWK, 29 bytes

{for(x=2^$2;$1>x;)$1-=x}$0=$1

Try it online!

It's reasonably fast when N and M aren't too far apart :-p

82 bytes, but fast

{x=1;for(y=2^$2;x<=$1;)x=lshift(x,1)
for(;x>y;$1>=x&&$1-=x)x=rshift(x, 1);print$1}

Try it online!

Japt, 6 bytes

¢tVn)Í

Try it

¢tVn)Í     :Implicit input of integers U=N & V=M
¢          :Convert U to binary string
 t         :Substring of length
  Vn       :  -V (i.e., the last V digits)
    )      :Convert to decimal

4 bytes

Using modulo & exponentiation methods, not operators.

u2pV

Try it

u2pV     :Implicit input of integers U=N & V=M
u        :U modulo
 2pV     :  2 raised to the power of V

C, 87 bytes

scanf("%d", &T);
while(T--){
   scanf("%d,%d", &N,&M);
   printf("%d",N&~(~0 << M));
}

SmileBASIC, 36 characters

INPUT N,M?N AND(1<<M)-1

There's basically only one solution to this...

J, 15 12 9 bytes

6 bytes thanks to @miles.

#.@#:~#&2

Previous 12-byte version

#.@({.~-)~#:

Usage

>> f =: #.@({.~-)~#:
>> 6 f 150
<< 22

Where >> is STDIN and << is STDOUT.

Explanation

#: converts n to base 2.

({.~-)~ then takes the last m digits from it

#. converts it back to base 2.

Previous 15-byte version:

2#.(0-[){.[:#:]

Usage

>> f =: 2#.(0-[){.[:#:]
>> 6 f 150
<< 22

Where >> is STDIN and << is STDOUT.

Explanation

[:#:] converts n to base 2.

(0-[){. then takes the last m digits from it

2#. converts it back to base 2.

Java

With whitespace to make readable:

long F(long M, long N) {
  M = 2<<M;
  while(N>=M) N-=M;
  return N;
}

Racket (scheme) 29 bytes

Kinda cheating because racket doesn't even have the % operator:

(λ(n m)(modulo n(expt 2 m)))

Golfscript - 16 chars

~]1>2/{~2\?(&n}/

For a single pair or numbers this would sufficient

~2\?(&

By the way, the / does not stand for division here :)

Perl, 31

<>;/ /,say($`&~(-1<<$'))while<>

Perl 5.10 or later, run with perl -E '<code here>'