mthadley/elm-byte/1.0.1

NOTE: this package is not compatible with Elm 0.19.1

Byte

A collection of utilities for working with a Byte.

Definition

type Byte

An opaque type respresenting an 8-bit unsigned integer.

fromInt : Int -> Byte

Converts an Int to a Byte.

fromInt 3 : Byte
toInt : Byte -> Int

Converts a Byte to an Int.

(fromInt 3 |> toInt) == 3

Guaranteed to be in the range: 0 <= n < 2^8.

Basic Operations

add : Byte -> Byte -> Byte

Adds two Bytes.

inc : Byte -> Byte

Increment a Byte.

sub : Byte -> Byte -> Byte

Subtracts the second Byte from the first.

dec : Byte -> Byte

Decrement a Byte.

isZero : Byte -> Bool

Returns True if the Byte is zero.

Bitwise Operations

and : Byte -> Byte -> Byte

Bitwise and (&) two Bytes.

or : Byte -> Byte -> Byte

Bitwise or (|) two Bytes.

xor : Byte -> Byte -> Byte

Bitwise xor two Bytes.

shiftLeft : Byte -> Carry

Shifts a Byte left.

shiftRight : Byte -> Carry

Shifts Byte right, preserving sign.

shiftRightZf : Byte -> Carry

Shifts Byte right, filling with zeroes.

rotateLeft : Byte -> Byte

Rotate a Byte left.

rotateRight : Byte -> Byte

Rotate a Byte right.

complement : Byte -> Byte

Bitwise complement (flips each bit).

getBit : Int -> Byte -> Bool

Returns a Bool indicating whether or not the bit is set.

lsbSet : Byte -> Bool

Returns a Bool indicating whether or not the least significant bit is set.

msbSet : Byte -> Bool

Returns a Bool indicating whether or not the most significant bit is set.

set : Int -> Byte -> Byte

Sets the nth bit of the Byte.

reset : Int -> Byte -> Byte

Resets the nth bit of the Byte.

setIf : Int -> Bool -> Byte -> Byte

Sets or resets the nth bit of the Byte.

highNibble : Byte -> Int

Returns an Int respresenting the higher 4 bits.

lowNibble : Byte -> Int

Returns an Int respresenting the lower 4 bits.

swap : Byte -> Byte

Swaps the high and low nibbles of the Byte.

Operations with a Carry.

These functions return a Carry instead of a Byte to check whether or not the operation overflowed the Byte. You can get the resulting byte using Carry.unwrap.

type alias Carry =
Carry Byte

A type alias for Carry result of a Byte operation.

addc : Byte -> Byte -> Carry

Adds two Bytes, returning a Carry.

incc : Byte -> Carry

Increment a Byte, returning a Carry.

subc : Byte -> Byte -> Carry

Subtracts the second Byte from the first, returning a carry.

decc : Byte -> Carry

Decrement a Byte, returning a Carry.

shiftLeft : Byte -> Carry

Shifts a Byte left.

shiftRight : Byte -> Carry

Shifts Byte right, preserving sign.

shiftRightZf : Byte -> Carry

Shifts Byte right, filling with zeroes.