[swift-users] Printing large hexadecimal values
swift at nattinger.net
Wed May 25 15:16:10 CDT 2016
%16x pads with spaces instead of zeros, use %016X for uppercase zero-padded output. `man 3 printf` will show the full spec (minus the objc-specific %@), or Apple probably documents it somewhere. It breaks down like this:
- x/X is a format saying it’s an int type and should be printed in hex with lowercase/uppercase a-f.
- ll is a flag saying the int is a long long.
- 16 says the output from that format spec should be 16 characters wide (right-aligned by default)
- 0 says left-pad with zeros instead of the default spaces.
> On May 25, 2016, at 12:10 PM, Ken Burgett <kenb at iotone.io> wrote:
> On 2016-05-25 12:00, Jens Alfke wrote:
>>> On May 25, 2016, at 11:11 AM, Ken Burgett <kenb at iotone.io> wrote:
>>> the "%llx" field is not getting interpreted...
>> You have to import Foundation to bring in the String.init(format:…)
>> method, which is bridged from Foundation's NSString class.
>> (This is a temporary inconvenience until the Swift standard library is
> Hi Jens,
> You are correct, the "%llx" works for UInt64, while "%16x" does not. "%llX" also works, producing an uppercase string.
> Should this be reported as a bug?
> Ken Burgett
> Principal Software Engineer
> Email: kenb at iotone.io
> Office: 530.693.4449
> Mobile: 831.332.6846
> URL: www.iotone.co
More information about the swift-users