> For the complete documentation index, see [llms.txt](https://calnix.gitbook.io/aave-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calnix.gitbook.io/aave-book/functions/common-functions/getreservefactor-getdecimals.md).

# getReserveFactor, getDecimals

## getReserveFactor

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FxPAZ4czGRgduegYgpAEW%2Fimage.png?alt=media&amp;token=9a78c5ae-c7d5-476b-8e2d-a7d3bc9c6a70" alt=""><figcaption></figcaption></figure>

* `getReserveFactor`, returns the value of `reserveFactor` as a uint256 variable.
* `reserveFactor`, amongst other data, is stored within the bitmap  `ReserveConfigurationMap`

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FzHgwA6Pt2Z9LkrFSnoM4%2Fimage.png?alt=media&amp;token=d9e490a9-6a3c-4c49-8ed1-b25fc34da9ac" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The reserve factor is a percentage of protocol interest which goes to the Aave Ecosystem Reserve. The rest of the borrow interest goes to the suppliers.
{% endhint %}

#### It does 3 things:

* Bitwise NOT of RESERVE\_FACTOR\_MASK: **`~`**`RESERVE_FACTOR_MASK`
* Bitwise AND: `data`` `**`&`** **`~`**`RESERVE_FACTOR_MASK`
* Right shift the result of the above by `RESERVE_FACTOR_START_BIT_POSITION`

#### RESERVE\_FACTOR\_MASK

```solidity
// 64 characters (we ignore the leading 0x)
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF
```

This is a 256-bit hexadecimal number, represented by 64 hexadecimal characters.&#x20;

* each hex character represents 4 bits => 4 \* 64 = 256 bits

In binary: first 176 bits are all `1` (represented by `F` in hexadecimal), followed by 16 zeros, and ending with another 64 bits of `1`.

{% hint style="info" %}
`0xF` can be directly interpreted in binary as such:&#x20;

`F` = 15 = 8 + 4 + 2 + 1 = `1111`
{% endhint %}

#### **`~`**`RESERVE_FACTOR_MASK`

The tilde is the bitwise NOT operator -> it flips the bits, changing 0s to 1s and 1s to 0s.

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2FXUUdKIYaeRf1s4uugUpo%2Fimage.png?alt=media&amp;token=1b8530c1-b0e6-47eb-a8f1-167a04a3caf6" alt=""><figcaption></figcaption></figure>

* Notice that only the bits 64-79 are now `F`, which corresponds to the range of bits that contain the `reserveFactor` value as seen in `ReserveConfigurationMap`
* #### **`~`**`RESERVE_FACTOR_MASK: 0x00..FFFF..00` &#x20;

#### `data`` `**`&`** **`~`**`RESERVE_FACTOR_MASK`

* `&` is the operator for bitwise AND operation
* AND operation returns `1` only if both the bits are `1`.
* `data AND 0x00..FFFF..00:`&#x20;
  * this means that it is only possible for the result of the operation to contain 1s within the range of 64-79
  * all other bits will be zero, as a bitwise ADD operation with a 0 will result in 0.
  * so we have the possibility of 1s occurring within 64-79 bit, if the corresponding bit in self.data, is also 1.

{% hint style="info" %}
The purpose of the mask is to wipe out all other irrelevant data, while extracting only the relevant portion of the bitmap
{% endhint %}

#### Right shift ( >> )

To illustrate this portion, let us assume the result so far is as follows:

```solidity
0x00000000000000000000000000000000000000000000 F0FF 0000000000000000 
```

* The result is right shifted by `RESERVE_FACTOR_START_BIT_POSITION`
* `RESERVE_FACTOR_START_BIT_POSITION = 64`

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2F7ToBo12EYY2eaxhvrySx%2Fimage.png?alt=media&amp;token=30a1db75-80b6-43ef-9061-7f07e1d8469f" alt=""><figcaption></figcaption></figure>

We see that the trailing zeros are dropped off, and replaced as leading zeros. Essentially, the section of bits corresponding to `reserveFactor` is moved all the way to the end.

**Why?**

**In short, right shifting such that the trailing zeros are removed so that the value is left-padded, results in the proper representation of a number.**

In Solidity, strings and bytes are padded on the lower-order (right) side with zero-bytes, while other types (such as numbers and addresses) are padded on the higher-order side.

As an example, this is how we would store the string "abcd" in one full word (32 bytes):

`0x6162636400000000000000000000000000000000000000000000000000000000`

This is how the number `0x61626364` would be stored:

`0x0000000000000000000000000000000000000000000000000000000061626364`

{% hint style="info" %}
uint256 (and other numbers) are left-padded.
{% endhint %}

## getDecimals

<figure><img src="https://1829638638-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0k7YXwFGMFZcsyqkM4q1%2Fuploads%2F9QpSCseHjMerUXcV2trf%2Fimage.png?alt=media&amp;token=af7040a4-9709-4466-a572-c35ff9766395" alt=""><figcaption></figcaption></figure>

* Process is similar to **getReserveFactor**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://calnix.gitbook.io/aave-book/functions/common-functions/getreservefactor-getdecimals.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
