Ignore:
Timestamp:
Sep 13, 2010, 12:59:27 PM (11 years ago)
Author:
mulligan
Message:

More work on bits, bytes and nibbles.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/Byte.ml

    r63 r64  
    3030  val get_bit_at: int -> byte -> bit
    3131  val set_bit_at: int -> bit -> byte -> byte option
     32*)
    3233
    3334  val (-&-): byte -> byte -> byte
    3435  val (-|-): byte -> byte -> byte
    3536  val (-^-): byte -> byte -> byte
     37(*
     38  val rotate_right: byte -> byte
     39  val rotate_left: byte -> byte
     40  val shift_right: byte -> byte
     41  val shift_left: byte -> byte
     42*)
    3643  val not: byte -> byte
    3744
     45(*
    3846  val map_nibble: (nibble -> nibble) -> byte -> byte
    3947  val map_bit: (bit -> bit) -> byte -> byte
     
    4250  val zip_nibble: (nibble -> nibble -> nibble) -> byte -> byte -> byte
    4351  val zip_bit: (bit -> bit -> bit) -> byte -> byte -> byte
    44   val pretty: byte -> string
     52  val to_string: byte -> string
    4553*)
    4654end
    4755
    48 module Byte(Nibble: NIBBLE): BYTE
    49   with type bit = Nibble.bit and type nibble = Nibble.nibble =
     56module Byte(Bit: BIT) (Nibble: NIBBLE): BYTE
     57  with type Nibble.bit = Bit.bit
     58  and  type nibble = Nibble.nibble =
    5059struct
    51   type bit = Nibble.bit
     60  type bit = Bit.bit
    5261  type nibble = Nibble.nibble
    5362  type byte = nibble * nibble
    5463
    55   let from_bits b1 b2 b3 b4 b5 b6 b7 b8 =
    56     let nibble
     64  let (-&-) (l1, l2) (r1, r2) = (Nibble.(-&-) l1 r1, Nibble.(-&-) l2 r2)
     65  let (-|-) (l1, l2) (r1, r2) = (Nibble.(-|-) l1 r1, Nibble.(-|-) l2 r2)
     66  let (-^-) (l1, l2) (r1, r2) = (Nibble.(-^-) l1 r1, Nibble.(-^-) l2 r2)
     67(*
     68  let shift_right (n1, n2) =
     69    let (b1, b2, b3, b4) = Nibble.to_bits n1 in
     70    let (b5, b6, b7, b8) = Nibble.to_bits n2 in
     71    let new_n1 = Nibble.from_bits (Bit.from_bool false) b1 b2 b3 in
     72    let new_n2 = Nibble.from_bits b4 b5 b6 b7 in
     73      (new_n1, new_n2)
     74  let shift_left (n1, n2) =
     75    let (b1, b2, b3, b4) = Nibble.to_bits n1 in
     76    let (b5, b6, b7, b8) = Nibble.to_bits n2 in
     77    let new_n1 = Nibble.from_bits b1 b2 b3 b4 in
     78    let new_n2 = Nibble.from_bits b5 b6 b7 (Bit.from_bool false) in
     79      (new_n1, new_n2)
     80  let rotate_right (n1, n2) =
     81    let (b1, b2, b3, b4) = Nibble.to_bits n1 in
     82    let (b5, b6, b7, b8) = Nibble.to_bits n2 in
     83    let new_n1 = Nibble.from_bits b8 b1 b2 b3 in
     84    let new_n2 = Nibble.from_bits b4 b5 b6 b7 in
     85      (new_n1, new_n2)
     86  let rotate_left (n1, n2) =
     87    let (b1, b2, b3, b4) = Nibble.to_bits n1 in
     88    let (b5, b6, b7, b8) = Nibble.to_bits n2 in
     89    let new_n1 = Nibble.from_bits b2 b3 b4 b5 in
     90    let new_n2 = Nibble.from_bits b5 b6 b7 b1 in
     91      (new_n1, new_n2)
     92*)
     93  let not (n1, n2) = (Nibble.not n1, Nibble.not n2)
    5794end
Note: See TracChangeset for help on using the changeset viewer.