i have 3 fields decimal, hexadecimal and octal and i want to convert the number typed in one field into the other 2 values but i can't tell the computer that the string I'm entering into the octal field is octal, with the hexadecimal i can use
but there is no
so i get wrong values when converting octal to decimal and hex
thats mt code
Code:
scanHexInt
Code:
scanOctInt
thats mt code
PHP:
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize decField = _decField;
@synthesize hexField = _hexField;
@synthesize octField = _octField;
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
self.decField.delegate = self;
self.hexField.delegate = self;
self.octField.delegate = self;
_changing = NO;
}
- (void)controlTextDidChange:(NSNotification *)notification
{
if ( _changing ) {
return;
}
_changing = YES;
// decimal to octal and hex
if([notification object] == self.decField) {
unsigned int n = [self.decField intValue];
NSString *h = [NSString stringWithFormat:@"%x", n];
NSString *o = [NSString stringWithFormat:@"%o", n];
[self.hexField setStringValue: h];
[self.octField setStringValue: o];
}
// octal to decimal and hex
if([notification object] == self.octField) {
unsigned int n = [self.octField intValue];
NSString *h = [NSString stringWithFormat:@"%x", n];
NSString *d = [NSString stringWithFormat:@"%d", n];
[self.hexField setStringValue: h];
[self.decField setStringValue: d];
}
// hex to octal and decimal
if([notification object] == self.hexField) {
NSScanner * scanner = [[NSScanner alloc] initWithString:[self.hexField stringValue]];
unsigned int n = 0;
[scanner scanHexInt: &n];
NSString *d = [NSString stringWithFormat:@"%d", n];
NSString *o = [NSString stringWithFormat:@"%o", n];
[self.decField setStringValue: d];
[self.octField setStringValue: o];
}
_changing = NO;
}
@end