# Casting an array of char to float

**URL:** <https://ziggit.dev/t/casting-an-array-of-char-to-float/3733>\
**Category:** Help\
**Tags:** language\
**Created:** [March 28, 2024, 3:35pm UTC](https://ziggit.dev/t/casting-an-array-of-char-to-float/3733 "2024-03-28T15:35:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke](https://ziggit.dev/letter_avatar_proxy/v4/letter/l/7ab992/32.png) [@Luke](https://ziggit.dev/u/Luke)\
**Post date:** [March 28, 2024, 3:35pm UTC](https://ziggit.dev/t/casting-an-array-of-char-to-float/3733/1 "2024-03-28T15:35:56Z")

</div>

Why this compiles:

```zig
    const from align(@alignOf(f32)) = [_]u8{ 1, 2, 3, 4 };
    const to: f32 = @bitCast(from); // [4]u8

```

But this does not?

```zig
    const from align(@alignOf(f32)) = [_]u8{ 1, 2, 3, 4 };
    const to: f32 = @bitCast(from[0..4]); // *align(4) const [4]u8

```

with

```zig
error: cannot @bitCast from '*align(4) const [4]u8'

```

---

<div class="post-metadata">

**Author:** ![Luke](https://ziggit.dev/letter_avatar_proxy/v4/letter/l/7ab992/32.png) [@Luke](https://ziggit.dev/u/Luke)\
**Post date:** [March 28, 2024, 3:40pm UTC](https://ziggit.dev/t/casting-an-array-of-char-to-float/3733/2 "2024-03-28T15:40:58Z")

</div>

Ok I tried to simplify my problem and ended up in a X/Y situation.

Here is what you are supposed to do here:

```zig
    const from align(@alignOf(f32)) = [_]u8{ 1, 2, 3, 4 };
    const to: f32 = @bitCast(from[0..4].*);

```

I’ll keep it here for reference.
