1

Having some issues converting a binary string to a Int.

The int value:

-294155939

The int value as binary:

11101110011101111000100101011101

The way im currently converting the binary to an int is like this

Int("11101110011101111000100101011101", radix:2) -> 4000811357

Int32("11101110011101111000100101011101", radix:2) -> nil

Int64("11101110011101111000100101011101", radix:2) -> 4000811357

I also tried UInt, obviously this didn't give the correct output as as UInt is unsigned and cant go below 0.

UInt("11101110011101111000100101011101", radix:2) -> 4000811357

Im unsure why my int representation of the binary string is coming out how it is. Is there another way to convert the binary to a signed int?

2
  • I have tried this already, it gives nil as the result Commented Aug 13, 2019 at 9:15
  • Int(Int32(bitPattern: UInt32("11101110011101111000100101011101", radix:2)!)) Commented Aug 13, 2019 at 9:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.