-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved checksum to it own extension file
- Loading branch information
1 parent
84730d9
commit e23379d
Showing
3 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//********************************************************************************************************************** | ||
// | ||
// Data+Checksum.swift | ||
// Adds a checksum property | ||
// Copyright ©2018 Peter Baumgartner. All rights reserved. | ||
// | ||
//********************************************************************************************************************** | ||
|
||
|
||
import Foundation | ||
|
||
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
|
||
public extension Data | ||
{ | ||
|
||
/// Calculates the checksum of the bytes contained in self | ||
/// | ||
/// Please note that the checksum is masked with 0xFF, so it will always be in the range 0...255 | ||
|
||
public var checksum : Int | ||
{ | ||
return self | ||
.map { Int($0) } | ||
.reduce(0,+) | ||
& 0xff | ||
} | ||
|
||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters