0 people like it.
Like the snippet!
Byte to bit list
Converts a byte list to a bit list. Takes a list of bytes and transforms it all into a flattened array of bits. For example,
> bytesToBits [|byte(0x0F);byte(0xF0)|] 16 ;;
val it : byte [] =
[|0uy; 0uy; 0uy; 0uy; 1uy; 1uy; 1uy; 1uy; 1uy; 1uy; 1uy; 1uy; 0uy; 0uy; 0uy;
0uy|]
1:
2:
3:
4:
5:
6:
|
let bitMasks = Seq.unfold (fun bitIndex -> Some((pown 2 bitIndex, bitIndex), bitIndex + 1)) 0
|> Seq.take 8
|> Seq.toList
|> List.rev
let byteToBitArray b = List.map (fun (bitMask, bitPosition) -> (b &&& bitMask) >>> bitPosition) bitMasks
|
val bitMasks : (int * int) list
Full name: Script.bitMasks
module Seq
from Microsoft.FSharp.Collections
val unfold : generator:('State -> ('T * 'State) option) -> state:'State -> seq<'T>
Full name: Microsoft.FSharp.Collections.Seq.unfold
val bitIndex : int
union case Option.Some: Value: 'T -> Option<'T>
val pown : x:'T -> n:int -> 'T (requires member get_One and member ( * ) and member ( / ))
Full name: Microsoft.FSharp.Core.Operators.pown
val take : count:int -> source:seq<'T> -> seq<'T>
Full name: Microsoft.FSharp.Collections.Seq.take
val toList : source:seq<'T> -> 'T list
Full name: Microsoft.FSharp.Collections.Seq.toList
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val rev : list:'T list -> 'T list
Full name: Microsoft.FSharp.Collections.List.rev
val byteToBitArray : b:int -> int list
Full name: Script.byteToBitArray
val b : int
val map : mapping:('T -> 'U) -> list:'T list -> 'U list
Full name: Microsoft.FSharp.Collections.List.map
val bitMask : int
val bitPosition : int32
More information