Commit e66f538972

Marc Tiehuis <marctiehuis@gmail.com>
2018-08-01 17:38:04
Add integer binary output format (#1313)
1 parent de949b7
Changed files (1)
std
std/fmt/index.zig
@@ -248,6 +248,11 @@ pub fn formatIntValue(
                     return formatAsciiChar(value, context, Errors, output);
                 }
             },
+            'b' => {
+                radix = 2;
+                uppercase = false;
+                width = 0;
+            },
             'd' => {
                 radix = 10;
                 uppercase = false;
@@ -874,6 +879,10 @@ test "fmt.format" {
         const value: u8 = 'a';
         try testFmt("u8: a\n", "u8: {c}\n", value);
     }
+    {
+        const value: u8 = 0b1100;
+        try testFmt("u8: 0b1100\n", "u8: 0b{b}\n", value);
+    }
     {
         const value: [3]u8 = "abc";
         try testFmt("array: abc\n", "array: {}\n", value);