July 4, 2011
6:16 p.m.
Hi guys I thought that printStringBase: 2 would do the trick but it only works for positive number. I would like to see the two complement representation of numbers. So I implemented something like that but I wonder if this is correct. | v | v := 10. String streamContents: [:s | 31 to: 1 by: -1 do: [:i | s nextPut: ((v bitAt: i) + 48) asCharacter ] . s contents] Integer readFrom: '0000000000000000000000000001010' base: 2 | v | v := -3. "1111111111101" String streamContents: [:s | 31 to: 1 by: -1 do: [:i | s nextPut: ((v bitAt: i) + 48) asCharacter ] . s contents ] '1111111111111111111111111111101' Now Integer readFrom: '11111111111111111111111111111101' base: 2 does not hold back -3 Stef