c - Create double by appending binary representations of two ints -
i'm trying create double appending binary representations of 2 ints. have now:
int = arc4random(); *(&i+1) = arc4random(); double d = *(double*)&i; i hoped double pointer use value in &i+1 address, , indeed case. when print binary representations of i , *(&i+1) , compare them binary representation of d, d composed appending *(&i+1) , i. *(&i+1) comes first?! why case?
edit: take @ answers of juan catalan , mark segal know what's right way of doing did using unions.
when print binary representations of , *(&i+1) , compare them binary representation of d, d composed appending *(&i+1) , i. *(&i+1) comes first?! why case?
the actual ordering of bytes depends upon 'endian-ness' of underlying hardware architecture.
with little endian architecture:
1) lowest address byte contains least significant 8 bits of total variable 2) highest address byte contains significant 8 bits of total variable.
Comments
Post a Comment