Re: char array to long

Sebastian Huber <[email protected]>
Newsgroups gmane.linux.suse.programming
Message-ID <[email protected]>
Jan Hendrik Berlin wrote:
[...]

>Ich hab einen long, und der maximalwert ist 0xffffffff. und ff steht immer für 
>ein Port! Auf jedem Port sind 8 IO-Pins! und das entspricht ja einem Byte!
>
>Ich möchte nun ein Stück Code haben, was mir aus einem array, was vier 
>einzelne Bytes enthält, diesen long Wert zusammensetzt! Und ich habs schon 
>probiert, aber ich hab da so meine Problemchen mit! Mein Code funktioniert 
>nicht!
>
uint32_t v = 0x12345678;
uint8_t b [4];
b [0] = v;
b [1] = v / 256;
b [2] = v / 65536;
b [3] = v / 16777216;

Damit sollte es doch gehen, und es sieht ganz portabel aus.

Ciao
	Sebastian



-- 
Um die Liste abzubestellen, schicken Sie eine Mail an:
    [email protected]
Um eine Liste aller verfügbaren Kommandos zu bekommen, schicken
Sie eine Mail an: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.