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?
···
On 2016-05-25 12:00, Jens Alfke wrote:
On May 25, 2016, at 11:11 AM, Ken Burgett <kenb@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
complete.)
—Jens
--
Ken Burgett
Principal Software Engineer
Email: kenb@iotone.io
Office: 530.693.4449
Mobile: 831.332.6846
URL: www.iotone.co
%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@iotone.io> wrote:
On 2016-05-25 12:00, Jens Alfke wrote:
On May 25, 2016, at 11:11 AM, Ken Burgett <kenb@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
complete.)
—Jens
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@iotone.io
Office: 530.693.4449
Mobile: 831.332.6846
URL: www.iotone.co
No, it’s correct behavior. You need to use the “ll” ("long long") modifier to specify that the parameter is a 64-bit value.
—Jens
···
On May 25, 2016, at 12:10 PM, Ken Burgett <kenb@iotone.io> wrote:
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?
I'm not sure this is strictly necessary, but I think it's a good idea to
explicitly use the "C*" types when doing formatting with varargs, to make
sure the calling convention matches what the callee expects:
String(format: "%llx", CLongLong(myNumber))
···
On Wed, May 25, 2016 at 1:19 PM, Jens Alfke via swift-users < swift-users@swift.org> wrote:
On May 25, 2016, at 12:10 PM, Ken Burgett <kenb@iotone.io> wrote:
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?
No, it’s correct behavior. You need to use the “ll” ("long long") modifier
to specify that the parameter is a 64-bit value.