Paul Kamp
Paul Kamp

Reputation: 113

how to use signed hexadecimal literals in swift?

I'm using libraries with C interface in swift and in C error codes often are set with hexadecimal defines corresponded to signed integer values.

Is there any ways to set hexadecimal literal to signed integer type, for example:

var k: Int32 = 0x80000001

?

Upvotes: 0

Views: 317

Answers (1)

Gereon
Gereon

Reputation: 17872

There's a special initializer for just this case:

let x = Int32(bitPattern: 0x80000001)
print(x) // -2147483647

Upvotes: 2

Related Questions