How can i convert an ulong to uint32? A simple cast is not working. What works for me is converting the long to a string and then again parsing the string to an int.
However this seems really wrong. Is there any better way?
How can i convert an ulong to uint32? A simple cast is not working. What works for me is converting the long to a string and then again parsing the string to an int.
However this seems really wrong. Is there any better way?
Copyright © 2021 Jogjafile Inc.
Like Paul R said, not sure what you mean by "simple cast". Both of the following are working fine for me (and, note, I'm testing with a ULONGLONG).
Direct cast:
unsigned long long val1 = (unsigned long long)75;
UInt32 val2 = (UInt32)val1;
NSLog( @"%qu, %lu", num1, num2 );
// OUTPUTS: 75, 75
Using NSNumber:
NSNumber* val1 = [NSNumber numberwithUnsignedLongLong:75];
NSNumber* val2 = [NSNumber numberwithUnsignedInteger:[val1 usignedIntegerValue]];
NSLog( @"%qu, %u", [num1 unsignedLongLongValue], [num2 unsignedIntegerValue]];
// OUTPUTS: 75, 75