1

Quick question, when I'm using encoders and decoders and I have a line like the following...

//.H File
@property uint64           docGroup;            //** declared in interface

//.M file
[aCoder encodeInt64:_docGroup forKey:@"docGroup"];

Will it properly store all '64' bits since I'm using an unsigned int64? I'm afraid it will leave the last bit behind. I'm curious what the behavior is in this case. Anyone know?

I could not find a function encodeUnsignedInt64, if there is one let me know.

Joseph Astrahan
  • 8,659
  • 12
  • 83
  • 154

2 Answers2

1

Yeah that should be fine; both signed and unsigned 64-bit integers use all 64-bits.

Test with (in a debugger):

uint64_t u64 = 0xfedcba9876543210ULL;
int64_t i64 = (int64_t)u64;
u64 = (uint64_t)i64;
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
1

If I understand the answers at Signed to unsigned conversion in C - is it always safe? correctly, converting uint64 to signed int64 is generally implementation dependent, but on architectures with a two's complement representation of negative numbers, the conversion does not change the bit pattern.

Therefore a conversion from uint64 to int64 and back to uint64 always yields the original value.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382