Hallo zusammen! wie kann man am besten eine negative 16bit Variable in zwei 8bit Variablen aufteilen und anschließend wieder zusammen setzen? Ist für ne UART Kommunikation. Bei positiven gehts recht einfach :
1 | uint_16t Zahl; |
2 | uint_8t lowbyte; |
3 | uint_8t highbyte; |
4 | |
5 | //Trennen
|
6 | |
7 | highbyte = ((Zahl>>8) & 0xFF); |
8 | lowbyte = ((Zahl>>0)) & 0xFF); |
9 | |
10 | //Zusammensetzen
|
11 | |
12 | Zahl = (lowbyte | (highbyte<<8)); |
Aber wie mach ich das mit negativen Zahlen? Gruss Holger