Skip to content

Correct the expected output in an example #58867

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

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

amartini51
Copy link
Member

@amartini51 amartini51 commented May 12, 2022

Confirmed in a REPL that the new value is correct:

  1> extension FixedWidthInteger { 
  2.     var binaryString: String { 
  3.         var result: [String] = [] 
  4.         for i in 0..<(Self.bitWidth / 8) { 
  5.             let byte = UInt8(truncatingIfNeeded: self >> (i * 8)) 
  6.             let byteString = String(byte, radix: 2) 
  7.             let padding = String(repeating: "0", 
  8.             count: 8 - byteString.count) 
  9.             result.append(padding + byteString) 
 10.         } 
 11.         return "0b" + result.reversed().joined(separator: "_") 
 12.     } 
 13. }
 14>  
 15> Int16.max.binaryString
$R0: String = "0b01111111_11111111"
 16> print((101 as UInt8).binaryString)
0b01100101

@amartini51 amartini51 requested a review from natecook1000 May 12, 2022 17:38
@amartini51
Copy link
Member Author

@swift-ci Please smoke test.

@amartini51 amartini51 requested a review from bjlanier July 6, 2022 23:55
@amartini51 amartini51 merged commit 1a7146f into swiftlang:main Aug 24, 2022
@amartini51 amartini51 deleted the binaryString_93165742 branch August 24, 2022 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants