# `log2`

## Description

Returns the base-2 logarithm of a number. Equivalent to `log(2, number)`.

## Syntax

Like many functions in DataPrime, `log2` supports [two notations](https://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

```dataprime
log2(number: number): number
```

```dataprime
(number: number).log2(): number
```

## Arguments

| Name   | Type   | Required | Description                                       |
| ------ | ------ | -------- | ------------------------------------------------- |
| number | number | **true** | The value whose base-2 logarithm will be computed |

## Example

**Use case: Apply a log base 2 transformation**

Compute the log base 2 of a numerical field and store the result in a new field.

### Example data

```json
{
    "some_value": 16
}
```

### Example query

```dataprime
create log_field from log2(some_value)
```

```dataprime
create log_field from some_value.log2()
```

### Example output

```json
{
    "some_value": 16,
    "log_field": 4
}
```
