D
DBC User
I have a value numberic 1 and I want to save it as 0x01 in the
character field instead of 1 in Ascii 31. How can I achive this?
character field instead of 1 in Ascii 31. How can I achive this?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
DBC said:I have a value numberic 1 and I want to save it as 0x01 in the
character field instead of 1 in Ascii 31. How can I achive this?
DBC said:For some reason it is coming back as 31. May be I am looking at a wrong
location. I will try again.
[email protected] said:If you're trying to make the value of a char 0x01, then
char a = 1;
should do the trick.
DBC User said:I have a value numberic 1 and I want to save it as 0x01 in the
character field instead of 1 in Ascii 31. How can I achive this?
DBC said:Carl,
I want to store the value in a char field that will be later used for
data transmission. I guess I can try the string format with (0:x) and
then convert it back to char.
DBC User said:Well it didn't work either. It is bringing back 31. Any ideas?
Dustin said:I have no idea why. The following code prints "1" to the console:
namespace CastTest
{
class Program
{
static void Main(string[] args)
{
char c = (char)1;
System.Console.WriteLine((int)c);
}
}
}

char c = (char)1;
puts the _value_ 1 in the character variable. It is not the character
'1', but whatever character has ASCII value 1.
Then, when you cast it back to int, you of course get 1.
If you want to store the character '1' in the variable and then print
out its int (ASCII ordinal value), then you do this:
char c = '1';
System.Console.WriteLine((int)c);
This will print 31.
* For the purists, I know that char doesn't store ASCII, it stores
Unicode, but I'm an old dog and I figure that more people will
understand what ASCII is.![]()
char c = (char)1;
puts the _value_ 1 in the character variable. It is not the character
'1', but whatever character has ASCII value 1.
Then, when you cast it back to int, you of course get 1.
If you want to store the character '1' in the variable and then print
out its int (ASCII ordinal value), then you do this:
char c = '1';
System.Console.WriteLine((int)c);
This will print 31.
DBC User said:For some reason it is coming back as 31. May be I am looking at a wrong
location. I will try again.
You might want to test this before posting. It prints 49. 31 is *not*
the ASCII value of '1'.
Dustin said:Sure, but that doesn't seem to be the original question:
"I have a value numberic 1 and I want to save it as 0x01 in the character
field instead of 1 in Ascii 31. How can I achive this?"
as, "I have no idea why this prints 1 to the console..." :-(
Dustin Campbell said:

Costello, but close.![]()
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.