Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init a BInt from a [UInt8] #56

Merged
merged 4 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/Swift-Big-Number-Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,19 @@ public struct BInt:
{
self.init(source)
}

/// Creates a new instance from a `[UInt8]` array
public init(bytes: [UInt8])
{
var num = BInt()

for byte in bytes
{
num = num << 8 | BInt(byte)
}

self.init(sign: num.sign, limbs: num.limbs)
}

//
//
Expand Down
12 changes: 7 additions & 5 deletions Swift-BigNumber.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0940;
LastUpgradeCheck = 1250;
ORGANIZATIONNAME = "Marcel Kröker";
TargetAttributes = {
AE8388A5203F1CAF00FAC88F = {
Expand Down Expand Up @@ -546,7 +546,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BigNumber-iOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yuzushioh.BigNumber-iOS";
PRODUCT_NAME = BigNumber;
Expand Down Expand Up @@ -577,7 +577,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BigNumber-iOS/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yuzushioh.BigNumber-iOS";
PRODUCT_NAME = BigNumber;
Expand All @@ -604,7 +604,7 @@
DEVELOPMENT_TEAM = "";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BigNumber-iOSTests/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yuzushioh.BigNumber-iOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -628,7 +628,7 @@
DEVELOPMENT_TEAM = "";
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "BigNumber-iOSTests/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.yuzushioh.BigNumber-iOSTests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -663,6 +663,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -720,6 +721,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
11 changes: 11 additions & 0 deletions Tests/Test_Initialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class Test_Initialization: XCTestCase {
XCTAssert(b.rawValue.limbs == [0, 0, 0, 0, 1])
}

func testUInt8Array()
{
// Array and expectation
// 0x0102030405 is 4328719365 in decimal
let array: [UInt8] = [0x01, 0x02, 0x03, 0x04, 0x05]
let expected: Int = 4328719365

let b = BInt(bytes: array)
XCTAssert(expected.description == b.description)
nathanfallet marked this conversation as resolved.
Show resolved Hide resolved
}

func testCodable() {
for i in 0..<50 {
let one = BInt(i)
Expand Down