473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Now number to ascii string

How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Thanks in advance.

Freddy Coal
Mar 30 '07 #1
9 1966
On Mar 30, 3:12 pm, "Freddy Coal" <freddyc...@gmail.withoutspan.com>
wrote:
How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Thanks in advance.

Freddy Coal
Your example is very cryptic. But the common way to convert a
numerical variable to the string equivalent is with the .ToString
method.

Mar 30 '07 #2
No Zacks, the .tostring return me the number, and I need the chars
equivalent for that number.

Again an example:

Dim Traza_dat As Int16 = 16448

I need traduce that number (16448) to two bytes string "@@"
<za***@construction-imaging.comwrote in message
news:11*********************@n76g2000hsh.googlegro ups.com...
On Mar 30, 3:12 pm, "Freddy Coal" <freddyc...@gmail.withoutspan.com>
wrote:
>How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Thanks in advance.

Freddy Coal

Your example is very cryptic. But the common way to convert a
numerical variable to the string equivalent is with the .ToString
method.

Mar 30 '07 #3
On Mar 30, 1:12 pm, "Freddy Coal" <freddyc...@gmail.withoutspan.com>
wrote:
How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Thanks in advance.

Freddy Coal
dim i as integer = 16448
dim firstchar as integer = i >8
dim secondchar as integer = i and &H00ff

console.writeline (convert.tochar(firstchar))
console.writeline(convert.tochar(secondchar))

Anyway, something like that. you might have to look up the exact vb
syntax (to much c# on the brain :).

--
Tom Shelton

Mar 30 '07 #4
Thanks Tom, this is I need, but you know a function in VB.Net, for make this
in one step?.

Freddy Coal

"Tom Shelton" <to*********@comcast.netwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
On Mar 30, 1:12 pm, "Freddy Coal" <freddyc...@gmail.withoutspan.com>
wrote:
>How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Thanks in advance.

Freddy Coal

dim i as integer = 16448
dim firstchar as integer = i >8
dim secondchar as integer = i and &H00ff

console.writeline (convert.tochar(firstchar))
console.writeline(convert.tochar(secondchar))

Anyway, something like that. you might have to look up the exact vb
syntax (to much c# on the brain :).

--
Tom Shelton

Mar 30 '07 #5
Hello Freddy,
How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".
Do I understand you correctly that you want it as hex? Then you can use
the following function. Please check for line breaks:

Private Function NumberToHexStrings(ByVal ThisNumber As Long, ByVal
StringLength As Byte) As String()
Dim retVal() As String

If StringLength = 0 Then
ReDim retval(-1)
Else
Dim ArrSize As Integer, t As Integer
Dim tNumber As String = Hex(ThisNumber)

While tNumber.Length Mod StringLength <0
tNumber = "0" & tNumber
End While

ArrSize = Fix((CDec(tNumber.Length) / CDec(StringLength)) + 0.5) - 1
ReDim retVal(ArrSize)

t = ArrSize

While t -1
retVal(t) = Strings.Right(tNumber, StringLength)
tNumber = Strings.Left(tNumber, tNumber.Length - StringLength)
t = t - 1
End While

End If

Return retVal
End Function
Use it like this:

Dim s() As String
s = NumberToHexStrings(16448, 2)
Best regards,

Martin
Mar 30 '07 #6
On Mar 30, 2:15 pm, "Freddy Coal" <freddyc...@gmail.withoutspan.com>
wrote:
Thanks Tom, this is I need, but you know a function in VB.Net, for make this
in one step?.

Freddy Coal

"Tom Shelton" <tom_shel...@comcast.netwrote in message

news:11**********************@l77g2000hsb.googlegr oups.com...
On Mar 30, 1:12 pm, "Freddy Coal" <freddyc...@gmail.withoutspan.com>
wrote:
How convert a number for the string equivalent?
For example:
I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".
Thanks in advance.
Freddy Coal
dim i as integer = 16448
dim firstchar as integer = i >8
dim secondchar as integer = i and &H00ff
console.writeline (convert.tochar(firstchar))
console.writeline(convert.tochar(secondchar))
Anyway, something like that. you might have to look up the exact vb
syntax (to much c# on the brain :).
--
Tom Shelton- Hide quoted text -

- Show quoted text -
Not built in. You'll need to put what i did into it's own function :)

--
Tom Shelton

Mar 30 '07 #7
Martin, Thanks for your answer, you know how convert a string to the hex
value?.

I have a string with "FFFEC3D1", I would like obtain the number in hex, how
define that variable?.

I try with system.convert.ToInt32, but I get an unhandled exception, "Input
string was not in a correct format"

My best regards.

Freddy Coal

"Martin H." <hk***@gmx.netwrote in message
news:46***********************@news.freenet.de...
Hello Freddy,
>How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Do I understand you correctly that you want it as hex? Then you can use
the following function. Please check for line breaks:

Private Function NumberToHexStrings(ByVal ThisNumber As Long, ByVal
StringLength As Byte) As String()
Dim retVal() As String

If StringLength = 0 Then
ReDim retval(-1)
Else
Dim ArrSize As Integer, t As Integer
Dim tNumber As String = Hex(ThisNumber)

While tNumber.Length Mod StringLength <0
tNumber = "0" & tNumber
End While

ArrSize = Fix((CDec(tNumber.Length) / CDec(StringLength)) + 0.5) - 1
ReDim retVal(ArrSize)

t = ArrSize

While t -1
retVal(t) = Strings.Right(tNumber, StringLength)
tNumber = Strings.Left(tNumber, tNumber.Length - StringLength)
t = t - 1
End While

End If

Return retVal
End Function
Use it like this:

Dim s() As String
s = NumberToHexStrings(16448, 2)
Best regards,

Martin

Mar 30 '07 #8
>I try with system.convert.ToInt32, but I get an unhandled exception, "Input
string was not in a correct format"
Which overload did you call? Make sure you call ToInt32(String,
Integer) and specify base 16 as the second argument.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 30 '07 #9
Hello Freddy,
I have a string with "FFFEC3D1", I would like obtain the number in hex, how
define that variable?.
To convert a hex string into numeric formats, you need to add the hex
header "&H". If you string is "&HFFFEC3D1" it will work.

Best regards,

Martin
Mar 31 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: cpptutor2000 | last post by:
Could some C++ guru please help me with this problem? Suppose I have a string representation of a very large number as: char *strNum = "1234"; now suppose I want to store this number with each...
5
by: b.stewart | last post by:
I have only been using C++ for a few afternoons and i still get confused at nearly every line i type so maybe someone here can help me. Im trying to write a small program that can change a...
12
by: george r smith | last post by:
Greetings, What is the C# code that returns the number of bytes in a string such as 32313131353131333432317E547E3132357E5553447E467E3536363031303030343835323632 7E307E56 It should be 80 I...
3
by: JSM | last post by:
Hi, I am just trying to port an existing simple encryption routine to C#. this routine simply adds/substracts 10 ascii characters to each character in a text file (except quotes). The routine...
6
by: Jovo Mirkovic | last post by:
Hi, I have to make a program which will generate 100,000 different ID numbers (for example 2345-9341-0903-3432-3432 ...) It must be really different, I meen it can not be a similar (like...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
15
by: Orchid | last post by:
Hello, I am looking to generate a unique ID field on MS. Access. The ID is with 10 digits with the combination of 5 Letters from the 26 letters and 5 Numbers from 1 to 9. The letters and numbers...
5
by: Peter Watkins | last post by:
I'd like to convert a little endian hex string: '00020000020000FC' to a number. I was going to use struct.unpack('>q', theString) but this is meant for a string where the bytes in the string...
8
by: sdlt85 | last post by:
Hi, the program is asking the user for a number ant he base of the number, then it will convert the number to decimal. But is running right only with base 2, 3, 4, 5, 6, 7, 8 but if I try 16 it is...
12
by: fermineutron | last post by:
I am trying to write a function which will convert a large ascii number, say 100 ascii digits, to its binary representation. It seems that evey algorithm I am trying to think of is backwards. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.