次のメソッドをコーディングして、Hex String を int に変換しました。
-(long)intFromHexString:(NSString*) string
{
char tempChar;
int temp;
tempChar=[string characterAtIndex:[string length]-1];
temp=strtol(&tempChar, NULL, 16);
NSLog(@"***>%c = %i",tempChar,temp);
return temp;
}
ほとんどの場合、正常に動作しますが、次のような大きな問題が発生することがあります。
2012-02-10 01:09:28.516 GameView[7664:f803] ***>7 = 7
2012-02-10 01:09:28.517 GameView[7664:f803] ***>7 = 7
2012-02-10 01:09:28.518 GameView[7664:f803] ***>D = 13
2012-02-10 01:09:28.519 GameView[7664:f803] ***>5 = 5
2012-02-10 01:09:28.520 GameView[7664:f803] ***>5 = 5
2012-02-10 01:09:28.520 GameView[7664:f803] ***>D = 13
2012-02-10 01:09:28.521 GameView[7664:f803] ***>4 = 4
2012-02-10 01:09:28.522 GameView[7664:f803] ***>4 = 4
2012-02-10 01:09:28.522 GameView[7664:f803] ***>5 = 5
2012-02-10 01:09:28.523 GameView[7664:f803] ***>4 = 1033 <------this
2012-02-10 01:09:28.524 GameView[7664:f803] ***>C = 12
2012-02-10 01:09:28.524 GameView[7664:f803] ***>B = 11
2012-02-10 01:09:28.525 GameView[7664:f803] ***>3 = 3
2012-02-10 01:09:28.526 GameView[7664:f803] ***>3 = 48 <------this
2012-02-10 01:09:28.527 GameView[7664:f803] ***>B = 11
私のコードの何が問題なのか誰か教えてもらえますか?