[swift-users] Printing large hexadecimal values

Kevin Nattinger swift at nattinger.net
Wed May 25 13:26:35 CDT 2016


“%08x” to zero-pad to 8 characters, “%08X" for uppercase A–F

% cat main.swift
import Foundation
let n = 10597059
print(String(format: "%x", n))
print(String(format: "%08x", n))
print(String(format: "%08X", n))
% swift main.swift
a1b2c3
00a1b2c3
00A1B2C3
%

> On May 25, 2016, at 10:54 AM, Jens Alfke via swift-users <swift-users at swift.org> wrote:
> 
> 
>> On May 25, 2016, at 10:16 AM, Ken Burgett via swift-users <swift-users at swift.org> wrote:
>> 
>> I wish to print a 64-bit unsigned integer as 8 hexadecimal digits, and I can't find any documentation on this.  Please advise.
> 
> print(String(format: “%llx”, n))		// typed from memory
> 
> —Jens
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list