# lv_utils.h (/api/private/misc/lv_utils_h)



<ApiSummary functions="4" />

Functions [#functions]

<ApiMember kind="function" name="lv_utils_bsearch" file="private/misc/lv_utils.h" line="48" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/misc/lv_utils.h#L48">
  lv_utils_bsearch [#lv_utils_bsearch]

  Searches base\[0] to base\[n - 1] for an item that matches \*key.

  ```c title=" " lineNumbers=1
  void * lv_utils_bsearch(const void *key, const void *base, size_t n, size_t size, int(*cmp)(const void *pRef, const void *pElement))
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name   | Type                                             | Description                                                                                    |
  | ------ | ------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
  | `key`  | `const void *`                                   | Pointer to item being searched for                                                             |
  | `base` | `const void *`                                   | Pointer to first element to search                                                             |
  | `n`    | `size_t`                                         | Number of elements                                                                             |
  | `size` | `size_t`                                         | Size of each element                                                                           |
  | `cmp`  | `int(*)(const void *pRef, const void *pElement)` | Pointer to comparison function (see unicode\_list\_compare() as a comparison function example) |

  **Returns:** `void *` — a pointer to a matching item, or NULL if none exists.

  <Callout type="info">
    The function cmp must return negative if it's first argument (the search key) is less that it's second (a table entry), zero if equal, and positive if greater.
  </Callout>

  <Callout type="info">
    Items in the array must be in ascending order.
  </Callout>
</ApiMember>

<ApiMember kind="function" name="lv_draw_buf_save_to_file" file="private/misc/lv_utils.h" line="57" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/misc/lv_utils.h#L57">
  lv_draw_buf_save_to_file [#lv_draw_buf_save_to_file]

  Save a draw buf to a file

  ```c title=" " lineNumbers=1
  lv_result_t lv_draw_buf_save_to_file(const lv_draw_buf_t *draw_buf, const char *path)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name       | Type                                                             | Description              |
  | ---------- | ---------------------------------------------------------------- | ------------------------ |
  | `draw_buf` | <ApiLink name="lv_draw_buf_t" display="const lv_draw_buf_t *" /> | pointer to a draw buffer |
  | `path`     | `const char *`                                                   | path to the file to save |

  **Returns:** <ApiLink name="lv_result_t" /> — LV\_RESULT\_OK: success; LV\_RESULT\_INVALID: error
</ApiMember>

<ApiMember kind="function" name="lv_swap_bytes_32" file="private/misc/lv_utils.h" line="64" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/misc/lv_utils.h#L64">
  lv_swap_bytes_32 [#lv_swap_bytes_32]

  Reverse the order of the bytes in a 32-bit value.

  ```c title=" " lineNumbers=1
  static uint32_t lv_swap_bytes_32(uint32_t x)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name | Type       | Description     |
  | ---- | ---------- | --------------- |
  | `x`  | `uint32_t` | a 32-bit value. |

  **Returns:** `uint32_t` — the value `x` with reversed byte-order.
</ApiMember>

<ApiMember kind="function" name="lv_swap_bytes_16" file="private/misc/lv_utils.h" line="77" url="https://github.com/lvgl/lvgl/tree/e1a0ad863f29742359bc680d6a7d973448ec2285/src/misc/lv_utils.h#L77">
  lv_swap_bytes_16 [#lv_swap_bytes_16]

  Reverse the order of the bytes in a 16-bit value.

  ```c title=" " lineNumbers=1
  static uint16_t lv_swap_bytes_16(uint16_t x)
  ```

  <span className="sr-only">
    Parameters
  </span>

  | Name | Type       | Description     |
  | ---- | ---------- | --------------- |
  | `x`  | `uint16_t` | a 16-bit value. |

  **Returns:** `uint16_t` — the value `x` with reversed byte-order.
</ApiMember>

Dependencies [#dependencies]

<FileIncludes includes="[&#x22;lvgl_public.h&#x22;]" includedBy="[&#x22;lvgl_private.h&#x22;]" />
