views:

1199

answers:

4

I am trying to convert an decimal number to it's character equivalent. For example:

int j = 65 // The character equivalent would be 'A'.

Sorry, forgot to specify the language. I thought I did. I am using the Cocoa/Object-C. It is really frustrating. I have tried the following but it is still not converting correctly.

char_num1        = [working_text characterAtIndex:i]; // value = 65    
char_num2         = [working_text characterAtIndex:i+1];    // value =  75
char_num3         = char_num1  + char_num2;   // value = 140          
char_str1   = [NSString stringWithFormat:@"%c",char_num3];  // mapped value = 229
char_str2   = [char_str2 stringByAppendingString:char_str1];

When char_num1 and char_num2 are added, I get the new ascii decimal value. However, when I try to convert the new decimal value to a character, I do not get the character that is mapped to char_num3.

+1  A: 

Most languages have a 'char' function, so it would be Char(j)

Mitch Wheat
A: 

It's quite often done with "chr" or "char", but some indication of the language / platform would be useful :-)

string k = Chr(j);
Steven Robbins
+4  A: 

Convert a character to a number in C:

int j = 'A';

Convert a number to a character in C:

char ch = 65;

Convert a character to a number in python:

j = ord('A')

Convert a number to a character in Python:

ch = chr(65)
vy32
+1  A: 

I'm not sure what language you're asking about. In Java, this works:

int a = 'a';
Asaph