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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -