Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. aligning hexadecimal output

aligning hexadecimal output

Scheduled Pinned Locked Moved C#
questioncsharp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rupel
    wrote on last edited by
    #1

    how can i tell C# to fill remaining space with '0'? when writing:

    string.Format("0x{0,4:X}",256);

    i get

    0x 100

    but i want

    0x0100

    the msdn-documentaition just says "...is padded with spaces" - no word on changing the fill-character. is this possible at all? :confused: :wq

    L R 2 Replies Last reply
    0
    • R Rupel

      how can i tell C# to fill remaining space with '0'? when writing:

      string.Format("0x{0,4:X}",256);

      i get

      0x 100

      but i want

      0x0100

      the msdn-documentaition just says "...is padded with spaces" - no word on changing the fill-character. is this possible at all? :confused: :wq

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      String.PadLeft Method Right-aligns the characters in this instance, padding on the left with a specified Unicode character for a specified total length. public string PadLeft(int, char); :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D

      R 1 Reply Last reply
      0
      • R Rupel

        how can i tell C# to fill remaining space with '0'? when writing:

        string.Format("0x{0,4:X}",256);

        i get

        0x 100

        but i want

        0x0100

        the msdn-documentaition just says "...is padded with spaces" - no word on changing the fill-character. is this possible at all? :confused: :wq

        R Offline
        R Offline
        Rupel
        wrote on last edited by
        #3

        current workaround (input is a Int16, so 4 chars are always enough)

        Int16 id = // set somewhere before
        string.Format("0x{0}{1}{2}{3:X}",(id<4096)?"0":"",(id<256)?"0":"",(id<16)?"0":"",id);

        but thats kind of X| :wq

        S 1 Reply Last reply
        0
        • L leppie

          String.PadLeft Method Right-aligns the characters in this instance, padding on the left with a specified Unicode character for a specified total length. public string PadLeft(int, char); :) MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D

          R Offline
          R Offline
          Rupel
          wrote on last edited by
          #4

          ah. not the way i thought, but an option. ;) thx :) :wq

          1 Reply Last reply
          0
          • R Rupel

            current workaround (input is a Int16, so 4 chars are always enough)

            Int16 id = // set somewhere before
            string.Format("0x{0}{1}{2}{3:X}",(id<4096)?"0":"",(id<256)?"0":"",(id<16)?"0":"",id);

            but thats kind of X| :wq

            S Offline
            S Offline
            Stephane Rodriguez
            wrote on last edited by
            #5

            int f = 256; string s = f.ToString("0000");


            And I swallow a small raisin.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups