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. 6 19164
"Rich Raffenetti" <ra********@com cast.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.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).PadL eft(4, "0"c) ?
--
Al Reid
Al, Thanks loads. It seems a little hokey but it works just like it is
documented.
"Al Reid" <ar*****@reidDA SHhome.com> wrote in message
news:uY******** ******@TK2MSFTN GP15.phx.gbl... "Rich Raffenetti" <ra********@com cast.net> wrote in message news:%2******** ********@TK2MSF TNGP12.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).PadL eft(4, "0"c) ? --
Al Reid
Hi Rich
String.Format(" {0:X4}", value)
HTH
Charles
"Rich Raffenetti" <ra********@com cast.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.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" <ra********@com cast.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
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*******@free net.de> wrote in message
news:uu******** ******@TK2MSFTN GP11.phx.gbl... "Rich Raffenetti" <ra********@com cast.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
"Rich Raffenetti" <ra********@com cast.net> wrote in message
news:OJ******** ******@TK2MSFTN GP14.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*******@free net.de> wrote in message news:uu******** ******@TK2MSFTN GP11.phx.gbl... "Rich Raffenetti" <ra********@com cast.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: david |
last post by:
Hi,
I have an application as follows:
MySQL database Back-Eend linked to MS Access Front-End and ASP Web
Application.
I require users to enter Serial Numbers such as:
0105123567 (10 digits), the first 4 being the month and year (mmyy)
|
by: david |
last post by:
Hi,
I have 2 text boxes on an ASP form.
A user enters a Serial Number in TB1 such as 0105123456, presses tab to
move to TB2, TB2 then displays the value of TB1 after a calculation has
been done.
(Based on a Serial Number range).
i.e. a user enters 0105123456, TB2 then adds 'x' qty to this number
depending on how many serial numbers are required.
|
by: samik_tanik |
last post by:
I need to export a datagrid to Excel.
I could did this. But, also need to keep the leading
zeros in the data.
How can I acheive this?
Any help would be appreciated.
--
Thanking you in anticipation,
Regards,
|
by: ram23 |
last post by:
Hi friends,
i need help ..
i am getting String value and i need to add leading zeros..
total length of Target string is 13char
eg: suppose if i get 12 as values..
it needs to convert into 0000000000012
|
by: leninv |
last post by:
Hi,
I have the following code where 'recs' is a record set.
For i=0 to recs.Fields.Count - 1
if i = 0 then
pindnt = string(itmlvl*2," ")
response.write pindnt & recs(i)
else
Response.write recs(i)
| |
by: JimmyKoolPantz |
last post by:
Task: Customer wants a script of the data that was processed in a
"CSV" file.
Problem: Zip-Code leading zeros are dropped
Basically we have a client that has requested a custom script for each
file that he has us process. He wants this in a Comma Delimited
Format.
|
by: LFM |
last post by:
I have a database setup that uses ODBC connections into SQL for read
only views to compare information from multiple sql databases in our
company. Most of the tables use the Employee ID as the primary key.
The problem is, one database formats the EmpID with leading zeros so
all EmpID's are 5 characters long. (ie, 00123, 01523) Another
database formats the EmpID as just the number of characters as the
number is (ie, 123, 1523). When you...
|
by: Monty |
last post by:
Hi All,
I am having a problem with leading zeros being stripped from fields in a CSV
file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing
a CSV file like so:
sSQL = "SELECT * FROM "
sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Microsoft.VisualBasic.FileIO.FileSystem.GetParentPath(msFile) &
_
|
by: Smokey Grindel |
last post by:
I basically need to remove any leading zeros and hyphens from a string...
regex seemed like the best rout and using a replace regex method... anyone
know of any good strings for this? The one I just made quick is ^0+| but
not having much experience with regex, is this the correct one?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |