User Tools

Site Tools


crc

CRC

This writes a CRC to an OrderedCollection.

| crc ws |
crc := 2636827734.
ws := WriteStream on: (OrderedCollection new).
0 to: -3 by: -1 do: [:idx | ws nextPut: ((crc bitShift: (idx * 8)) bitAnd: 255)].
ws  -> OrderedCollection(86 204 42 157 )

This reads it back.

|crc coll |

coll :=  #(86 204 42 157) asOrderedCollection.
crc := coll at: 4.
crc := crc bitShift: 8.
crc := crc bitOr: (coll at: 3).
crc :=crc bitShift: 8.
crc := crc bitOr: (coll at: 2).
crc := crc bitShift: 8.
crc := crc bitOr: (coll at: 1).
crc -> 2636827734

A simpler version

|crc coll |

coll :=  #(86 204 42 157) asOrderedCollection.
crc := coll at: 4.
coll size - 1 to: 1 by: -1 do: [:index|
	crc := crc bitShift: 8.
	crc := crc bitOr: (coll at: index).].
crc -> 2636827734
crc.txt · Last modified: 2015/05/13 11:35 by 127.0.0.1