Bit Manipulator/Reader Introduction

There are often times that we have challenges which require communication of some sort (such as in team KOTH), where density of information may be more important than density of code. There are a number of compression techniques that can allow us to convey more information in less space, but for simple data flags, sometimes flipping bits themselves can be a great way to achieve desired data density.

Challenge

Write a program or function in the language of your choice that can take an integer to be manipulated (must handle at least 32 bit), a start bit position (integer), a number of bits to manipulate (integer), and a manipulation mode (integer), and returns the original integer manipulated in the way specified below. In addition, write a second program or function that serves as a bit reader, taking in an integer, a start bit position (integer), and a number of bits to read (integer), and returns an integer consisting of just that group of bits shifted down, and every other bit as 0.

Some further details and rules are as follows:


The first argument will be an integer, signed or unsigned.
The second argument will be the bit position to start from (counting from least significant bit, zero-indexed).
The third argument will be the number of bits to be read/manipulated, moving up in bit significance from the start bit. If not given as an argument, the value should default to 1.
The fourth argument (manipulator only) will be the manipulation mode:


When passed a 0 or null value, the behavior will be to flip (xor) all of the specified bits (default if no value given).
When passed a positive value, the behavior will be to set all of the specified bits to 1.
When passed a negative value, the behavior will be to set all of the specified bits to 0.

The return value of the manipulator function should be the initial integer with the above bit manipulations applied.
The return value of the reader function should be the start bit shifted to the least significant bit, and every bit beyond the length of bits set to 0.
Assume that only valid input will be used. Don't worry about error handling.


The winner will be determined by the shortest sum of the length of both programs/functions. They will be selected in at least 7 days, or if/when there have been enough submissions. In the event of a tie, the answer that came earlier wins.

Examples

Here's a few examples of input and output that your code should be able to handle. I've golfed both functions in JavaScript that I can release if people want to test their results, but otherwise I'll probably wait a few days before I post it up.

Manipulator

F(0, 2) =&gt; 4 (0 =&gt; 100)

F(4, 2) =&gt; 0 (100 =&gt; 0)

F(0, 2, 4) =&gt; 60 (0 =&gt; 111100)

F(170, 2, 4, 0) =&gt; 150 (10101010 =&gt; 10010110)

F(170, 2, 4, 1) =&gt; 190 (10101010 =&gt; 10111110)

F(170, 2, 4, -1) =&gt; 130 (10101010 =&gt; 10000010)

F(0, 31) =&gt; (+/-)2147483648 (0 =&gt; 10000000000000000000000000000000)


Reader

F(0, 2) =&gt; 0 (0 =&gt; 0)

F(4, 2) =&gt; 1 (100 =&gt; 1)

F(60, 2, 4) =&gt; 15 (111100 =&gt; 1111)

F(170, 2, 4) =&gt; 10 (10101010 =&gt; 1010)

F((+/-)2147483648, 0, 32) =&gt; (+/-)2147483648 (10000000000000000000000000000000 =&gt; 10000000000000000000000000000000)
JavaScript (ES6), 75 bytes

Saved 4 bytes thanks to @Mwr247

Manipulator: (47 bytes)

(a,b,c=1,d=0,z=(1&lt;&lt;c)-1&lt;&lt;b)=&gt;d?d&lt;0?a&amp;~z:a|z:a^z


Reader: (28 bytes)

(a,b,c=1)=&gt;a&gt;&gt;b&amp;(1&lt;&lt;c-1)*2-1


How it works

Manipulator

The first thing we need to do is figure out the number that has c bits set, starting at the bth bit. Possibly the best way to do this is z=(1&lt;&lt;c)-1&lt;&lt;b, which works like so:

b  c    1&lt;&lt;c     -1     &lt;&lt;b    z
2  1      10     01    0100    4
2  2     100    011   01100   12
2  3    1000   0111  011100   28
1  4   10000  01111  011110   30


Now we take into account d. For case 0, we flip the bits with a^z; for case 1, we set the bits to 1 with a|z; for case -1, we set the bits to 0 with a&amp;~z.