jeudi 31 mai 2018

Formating C++ integers

This is a follow up question to this question:

How do I print bytes as hexadecimal?

The question above however, doesn't answer exactly what I need.

What is the c++ 11 equivalent of C# ToString("X8") for numbers?

an example of what I'm talking about in C#:

using System;
using System.Globalization;

public class Example

{
   public static void Main()

   {
    int value;
    value = 0x2045e;
    Console.WriteLine(value.ToString("x"));
    Console.WriteLine(value.ToString("X"));
    Console.WriteLine(value.ToString("X8"));

    value = 123456789;
    Console.WriteLine(value.ToString("X"));
    Console.WriteLine(value.ToString("X2"));
  }
}

/* 
2045e
2045E
0002045E
75BCD15
75BCD15 
*/

Aucun commentaire:

Enregistrer un commentaire