hello,
i've a 4 character string stored in a 4byte value (lets say an 32 bit
integer).
the integer holds the value:
char[3]*255^3+char[2]*255^2+char[1]*255^1+char[0]*255^0.
how can i convert this integer back to string?
thx
rené 4 2909
On Jul 25, 9:43 am, ohmmega <sho...@gmx.atw rote:
i've a 4 character string stored in a 4byte value (lets say an 32 bit
integer).
the integer holds the value:
char[3]*255^3+char[2]*255^2+char[1]*255^1+char[0]*255^0.
how can i convert this integer back to string?
You should be *very* clear about the differences between characters
and bytes. In .NET, each char is represented as *two* bytes (a UTF-16
code point).
Now, if you mean you've got an integer that you want to be converted
into a byte array and then treated as ASCII text, you can use
BitConverter to go from the integer to a byte array, then
Encoding.ASCII to go from the byte array to text.
Jon
On 25 Jul., 10:45, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
You should be *very* clear about the differences between characters
and bytes. In .NET, each char is represented as *two* bytes (a UTF-16
code point).
Now, if you mean you've got an integer that you want to be converted
into a byte array and then treated as ASCII text, you can use
BitConverter to go from the integer to a byte array, then
Encoding.ASCII to go from the byte array to text.
Jon
usually i'm aware about the difference - anyway thank's for the
casting conclusion.
so: yes, i meant ASCII text and i've made a small method for my prob:
<code>
private string IntToString(int intVal)
{
byte[] bVal = BitConverter.Ge tBytes(intVal);
System.Text.ASC IIEncoding asciiEncoding = new
System.Text.ASC IIEncoding();
return asciiEncoding.G etString(bVal);
}
</code>
work's great - thank's for the thought-provoking impulse :)
On Jul 25, 10:55 am, ohmmega <sho...@gmx.atw rote:
<snip>
so: yes, i meant ASCII text and i've made a small method for my prob:
<code>
private string IntToString(int intVal)
{
byte[] bVal = BitConverter.Ge tBytes(intVal);
System.Text.ASC IIEncoding asciiEncoding = new
System.Text.ASC IIEncoding();
return asciiEncoding.G etString(bVal); }
</code>
work's great - thank's for the thought-provoking impulse :)
One thing you might want to change - there's no need to create a new
ASCIIEncoding each time. Just use:
return Encoding.ASCII. GetString(bVal) ;
Jon
On 25 Jul., 11:59, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
On Jul 25, 10:55 am, ohmmega <sho...@gmx.atw rote:
<snip>
so: yes, i meant ASCII text and i've made a small method for my prob:
<code>
private string IntToString(int intVal)
{
byte[] bVal = BitConverter.Ge tBytes(intVal);
System.Text.ASC IIEncoding asciiEncoding = new
System.Text.ASC IIEncoding();
return asciiEncoding.G etString(bVal); }
</code>
work's great - thank's for the thought-provoking impulse :)
One thing you might want to change - there's no need to create a new
ASCIIEncoding each time. Just use:
return Encoding.ASCII. GetString(bVal) ;
Jon
oops :)
that's really fine
thx This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Arvid Andersson |
last post by:
Hello, I need to convert a string to a number, but the string can
contain +,-,* and / as well as parenthesis. For example, if I have the
string "30/(6+9)" I would like a function that returned the number 2.
I actually wrote a java function that did this a couple of years ago, in
school, as an excersise in "binary trees". I lost it, and most of my
programming knowledge, but I figured perhaps there is a way to do this
easily in python? It...
|
by: LRW |
last post by:
Below is some of the code I'm using.
I have a PHP page generating a list of items. I've made it so that
each one has a radiobutton with a unique value. You can click on the
radiobutton and it will change the value of a text field to the value
of the radiobutton--all that works fine!
Now, I need to also have it populate a textfield with the value of a
textfield in the row that's selected.
I can make unique field names, no problem. I...
|
by: KB |
last post by:
Hi,
This may be a rudimentary question:
How to convert a string like '777' to an octal integer like 0777,
so that it can be used in os.chmod('myfile',0777)?
I know the leading zero is important in os.chmod.
KB
|
by: linzhenhua1205 |
last post by:
I want to parse a string like C program parse the command line into
argc & argv.
I hope don't use the array the allocate a fix memory first, and don't
use the memory allocate function like malloc.
who can give me some ideas?
The following is my program, but it has some problem. I hope someone
would correct it.
////////////////////////////
//Test_ConvertArg.c
////////////////////////////
|
by: Bell, Kevin |
last post by:
I'm building a dictionary from values a database and upon print the
dictionary I see key value pairs like this:
u'Briarcliff' : ,
u'Shumway' :
do I need to slice off the "u", or anything? I know it has something to
do with unicode but I don't know how to treat it.
| |
by: Akihiro KAYAMA |
last post by:
Hi all.
I would like to ask how I can implement string-like class using tuple
or list. Does anyone know about some example codes of pure python
implementation of string-like class?
Because I am trying to use Python for a text processing which is
composed of a large character set. As the character set is wider than
UTF-16(U+10FFFF), I can't use Python's native unicode string class.
|
by: Zontar |
last post by:
I'm trying to improve performance on a query, and I was wondering if this is possible in Access.
Let's say I have a table with one text column and one row.
In that column, I have a field name from another table . This fieldtable gets updated from a form, but it never has more than one row in it.
So an example value in my look like this:
.
|
by: mark4asp |
last post by:
How can I use name:value pairs like an array?
1. I want to load data on to the page which will be used to populate a
list box (see example below):
<html>
<head>
<script type="text/javascript">
var aInvestor = {1448:"4Imprint Group plc Pension Scheme",
1061:"Aargau Pensionskasse",659:"ABB Koncernens Pensionsstiftelse",
|
by: chuckzter |
last post by:
I'm in a bit of a pickle here. I need to pass the variable @uname which gets a value from a text box to a statement on one of my stored procedures in SQL server and return an output on my form.
Here is the code:
in .net
cmd = New SqlCommand
cmd.CommandText = "sp_TransData"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@unamex",SqlDbType.VarChar,15)
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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...
| |