|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Hex with leading zeros to string?How can one format an integer into a hex string with leading zeros? Suppose
an integer is 512 which in Hex is 200. I wish to print the 4-byte integer as 0200 or even 0x0200. The HEX function doesn't create leading zeros. The Format function (format(value,"X") doesn't create leading zeros. I believe there should be a simple way that doesn't involving measuring and padding the string. "Rich Raffenetti" <raffene***@comcast.net> wrote in message Hex(value).PadLeft(4, "0"c) ?news:%23LJyordLGHA.1424@TK2MSFTNGP12.phx.gbl... > How can one format an integer into a hex string with leading zeros? > Suppose an integer is 512 which in Hex is 200. I wish to print the 4-byte > integer as 0200 or even 0x0200. The HEX function doesn't create leading > zeros. The Format function (format(value,"X") doesn't create leading > zeros. > > I believe there should be a simple way that doesn't involving measuring > and padding the string. > How about -- Al Reid Al, Thanks loads. It seems a little hokey but it works just like it is
documented. Show quoteHide quote "Al Reid" <arei***@reidDASHhome.com> wrote in message news:uYXxj2dLGHA.2628@TK2MSFTNGP15.phx.gbl... > "Rich Raffenetti" <raffene***@comcast.net> wrote in message > news:%23LJyordLGHA.1424@TK2MSFTNGP12.phx.gbl... >> How can one format an integer into a hex string with leading zeros? >> Suppose an integer is 512 which in Hex is 200. I wish to print the >> 4-byte integer as 0200 or even 0x0200. The HEX function doesn't create >> leading zeros. The Format function (format(value,"X") doesn't create >> leading zeros. >> >> I believe there should be a simple way that doesn't involving measuring >> and padding the string. >> > How about > Hex(value).PadLeft(4, "0"c) ? > > > > -- > > Al Reid > > > > > > Hi Rich
String.Format("{0:X4}", value) HTH Charles Show quoteHide quote "Rich Raffenetti" <raffene***@comcast.net> wrote in message news:%23LJyordLGHA.1424@TK2MSFTNGP12.phx.gbl... > How can one format an integer into a hex string with leading zeros? > Suppose an integer is 512 which in Hex is 200. I wish to print the 4-byte > integer as 0200 or even 0x0200. The HEX function doesn't create leading > zeros. The Format function (format(value,"X") doesn't create leading > zeros. > > I believe there should be a simple way that doesn't involving measuring > and padding the string. > "Rich Raffenetti" <raffene***@comcast.net> schrieb Value.ToString("X4")> How can one format an integer into a hex string with leading zeros? > Suppose an integer is 512 which in Hex is 200. I wish to print the > 4-byte integer as 0200 or even 0x0200. The HEX function doesn't > create leading zeros. The Format function (format(value,"X") > doesn't create leading zeros. > > I believe there should be a simple way that doesn't involving > measuring and padding the string. Armin Thanks to all for the three options. I like Value.ToString("X4") best but I
also like the padleft method for other uses. Having done mostly VB6, I am new to .Net programming and am interested in recommended books that would contain these kinds of details. Show quoteHide quote "Armin Zingler" <az.nospam@freenet.de> wrote in message news:uuZn0YlLGHA.3260@TK2MSFTNGP11.phx.gbl... > "Rich Raffenetti" <raffene***@comcast.net> schrieb >> How can one format an integer into a hex string with leading zeros? >> Suppose an integer is 512 which in Hex is 200. I wish to print the >> 4-byte integer as 0200 or even 0x0200. The HEX function doesn't >> create leading zeros. The Format function (format(value,"X") >> doesn't create leading zeros. >> >> I believe there should be a simple way that doesn't involving >> measuring and padding the string. > > Value.ToString("X4") > > > Armin I like the String.Format(...) version, myself ;-)
Charles Show quoteHide quote "Rich Raffenetti" <raffene***@comcast.net> wrote in message news:OJIwWmqLGHA.2696@TK2MSFTNGP14.phx.gbl... > Thanks to all for the three options. I like Value.ToString("X4") best but > I also like the padleft method for other uses. > > Having done mostly VB6, I am new to .Net programming and am interested in > recommended books that would contain these kinds of details. > > "Armin Zingler" <az.nospam@freenet.de> wrote in message > news:uuZn0YlLGHA.3260@TK2MSFTNGP11.phx.gbl... >> "Rich Raffenetti" <raffene***@comcast.net> schrieb >>> How can one format an integer into a hex string with leading zeros? >>> Suppose an integer is 512 which in Hex is 200. I wish to print the >>> 4-byte integer as 0200 or even 0x0200. The HEX function doesn't >>> create leading zeros. The Format function (format(value,"X") >>> doesn't create leading zeros. >>> >>> I believe there should be a simple way that doesn't involving >>> measuring and padding the string. >> >> Value.ToString("X4") >> >> >> Armin > >
master volume control in winmm using namespaces
VB.NET (2005); Sqlce ? How to get worksheet names from an excel file? Problem with Structures using FieldOffset -- BUG? Changing default printer..... Is Office required on End user's PC ? VB.Net code to upsize Access DB to SQL Express? Array Objects pointers, value types reference types?? VB.Net vs Access vs Deployment Streams, Files, Readers and Writers |
|||||||||||||||||||||||