aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/BitOps/Signedness.php
blob: 80cd03b69a4c771769715a491ff220f3887e4abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php

declare(strict_types=1);

namespace Nsfisis\Waddiwasi\BitOps;

enum Signedness
{
    case Unsigned;
    case Signed;

    public static function fromSignBit(int $b): self
    {
        return $b === 0 ? self::Unsigned : self::Signed;
    }

    public function negated(): self
    {
        return match ($this) {
            self::Unsigned => self::Signed,
            self::Signed => self::Unsigned,
        };
    }
}