Skip to content

foldfelis-QO/GrayCode.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1492edf · Sep 26, 2022

History

15 Commits
Aug 21, 2022
Sep 26, 2022
Aug 30, 2022
Aug 21, 2022
Aug 21, 2022
Aug 21, 2022
Sep 6, 2022
Sep 26, 2022

Repository files navigation

GrayCode

Primitive types of Gray codes introduced by Frank Gray

Stable Dev Build Status Coverage

Quick start

The package can be installed with the Julia package manager. From the Julia REPL, type ] to enter the Pkg REPL mode and run:

pkg> add GrayCode

Usage

To use Gray code to represent integer:

julia> using GrayCode

julia> Gray8(5)
Gray8(5)

julia> Gray16(5)
Gray16(5)

julia> Gray32(5)
Gray32(5)

julia> Gray64(5)
Gray64(5)

julia> Gray128(5)
Gray128(5)

julia> Gray(5)
Gray64(5)

To convert Gray code to 2's complement representation:

julia> typeof(Integer(Gray8(5)))
UInt8

julia> Integer(Gray8(5))
0x05

Bit pattern of Gray codes

julia> @. bitstring(Gray8(0:7))
8-element Vector{String}:
 "00000000"
 "00000001"
 "00000011"
 "00000010"
 "00000110"
 "00000111"
 "00000101"
 "00000100"