Sha256: 5bd8ba13b59c15564ceee9798c77eb42d839415b8e2532dc7bf158fe003a7eda

Contents?: true

Size: 433 Bytes

Versions: 98

Compression:

Stored size: 433 Bytes

Contents

module Hexadecimal

open System

let private isValid char = "0123456789ABCDEF".Contains(string char)

let private charToDecimal (char: char) =
    if Char.IsDigit(char) then (int)char - (int)'0'
    else (int)(char) - (int)'A' + 10

let toDecimal(input: string) = 
    let chars = input.ToUpperInvariant().ToCharArray()
    if Array.forall isValid chars then Array.fold (fun acc c -> acc * 16 + charToDecimal c) 0 chars
    else 0

Version data entries

98 entries across 98 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/hexadecimal/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/hexadecimal/Example.fs