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



<ApiSummary functions="4" />

Functions [#functions]

<ApiMember kind="function" name="lv_utils_bsearch" file="misc/lv_utils.h" line="49" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_utils.h#L49">
  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`    | <ApiLink name="size_t" />                        | Number of elements                                                                             |
  | `size` | <ApiLink name="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="misc/lv_utils.h" line="58" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_utils.h#L58">
  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="misc/lv_utils.h" line="65" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_utils.h#L65">
  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`  | <ApiLink name="uint32_t" /> | a 32-bit value. |

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

<ApiMember kind="function" name="lv_swap_bytes_16" file="misc/lv_utils.h" line="78" url="https://github.com/lvgl/lvgl/tree/a7b95c5b0839ce901c09c205610bc2c77cc3345d/src/misc/lv_utils.h#L78">
  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`  | <ApiLink name="uint16_t" /> | a 16-bit value. |

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

Dependencies [#dependencies]

<FileIncludes includes="[&#x22;lv_types.h&#x22;, &#x22;lv_draw_buf.h&#x22;]" transitiveIncludes="[&#x22;lv_area.h&#x22;, &#x22;lv_assert.h&#x22;, &#x22;lv_color.h&#x22;, &#x22;lv_color_op.h&#x22;, &#x22;lv_conf_internal.h&#x22;, &#x22;lv_conf_kconfig.h&#x22;, &#x22;lv_image_dsc.h&#x22;, &#x22;lv_log.h&#x22;, &#x22;lv_math.h&#x22;, &#x22;lv_mem.h&#x22;, &#x22;lv_palette.h&#x22;, &#x22;lv_string.h&#x22;]" />
