# Function Not returning right value

**URL:** <https://users.rust-lang.org/t/function-not-returning-right-value/141369>\
**Category:** help\
**Created:** [July 19, 2026, 7:12pm UTC](https://users.rust-lang.org/t/function-not-returning-right-value/141369 "2026-07-19T19:12:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robro0.625](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@Robro0.625](https://users.rust-lang.org/u/Robro0.625)\
**Post date:** [July 19, 2026, 7:12pm UTC](https://users.rust-lang.org/t/function-not-returning-right-value/141369/1 "2026-07-19T19:12:32Z")

</div>

Hello, I am working on a chess engine and have this method on the board struct

```rust
fn get_black_pawn_right_attacks(&self) -> u64{
   let out = (self.bp << 7) & self.aw;
   eprintln!("OUT: 0x{:016x}",out);
   return out;
}

```

I call it here inside another struct.

```rust
        eprintln!("right: 0x{:016}",self.board.get_black_pawn_right_attacks());

```

This causes

```rust
OUT: 0x0080000000000000
right: 0x36028797018963968

```

to be printed.  
How are the 2 values different? What is happening?

---

<div class="post-metadata">

**Author:** ![ntova](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@ntova](https://users.rust-lang.org/u/ntova)\
**Post date:** [July 19, 2026, 7:19pm UTC](https://users.rust-lang.org/t/function-not-returning-right-value/141369/2 "2026-07-19T19:19:44Z")

</div>

> [@Robro0.625](#):
>
> `eprintln!("right: 0x{:016}",self.board.get_black_pawn_right_attacks());`

You are missing the `x` at the end of the formatstring.

---

<div class="post-metadata">

**Author:** ![Robro0.625](https://avatars.discourse-cdn.com/v4/letter/r/ac8455/32.png) [@Robro0.625](https://users.rust-lang.org/u/Robro0.625)\
**Post date:** [July 19, 2026, 7:22pm UTC](https://users.rust-lang.org/t/function-not-returning-right-value/141369/3 "2026-07-19T19:22:21Z")

</div>

Thank you, I must be blind

---

<div class="post-metadata">

**Author:** ![nerditation](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nerditation](https://users.rust-lang.org/u/nerditation)\
**Post date:** [July 19, 2026, 11:48pm UTC](https://users.rust-lang.org/t/function-not-returning-right-value/141369/4 "2026-07-19T23:48:15Z")

</div>

> [@Robro0.625](#):
>
> ```rust
> eprintln!("OUT: 0x{:016x}",out);
> 
> ```

just a reminder, you don't need the `0x` prefix, you can use the _alternate_ format for `UpperHex` and `LowerHex`, then the value will be formatted with a `0x` prefiix.

these two give the exact same result:

```rust
   eprintln!("OUT: {:#018x}",out);
   eprintln!("OUT: 0x{:016x}",out);

```

be aware: the prefix in the alternate format is always in lower case `0x`, even for the `UpperHex` formatter, which formats the hex **digits** in upper case; and the width specifier includes the `0x` prefix too.
