c++ - Change byte in int - casting byte to an integer -
I am streaming data from the server. Server sends different BigAndDan variables, but sends bytes too (representing number is). Accepts one According to the above, I am changing the wrong part of First of all: Second: Reading 8 bits in a (perhaps) 32 bit memory space and the correct end to keep 8 bits C ++ (as you say your comment). It is actually below your CPU because the endurance CPU Do not read the value in an actual (int length, char * array) of my
SocketClient.read overload . I want to pass an integer variable indicator in this function (in unsigned byte) in the get 0-255 value .
What I've tried:
unsigned int UNSIGNED_BYTE; Socket.read (1, & ((* Four *) and UNSIGNED_BYTE) [0]); // I am changing 1 byte of a variable - C ++ uses little endian / I know that reads function 6, and that is what I got by 1 byte stady :: COAT & lt; & Lt; (Int * (* four *); UNSIGNED_BYTE) [0] to be & lt; & Lt; ") \ N"; // 6 - Correct std :: cout & lt; & Lt; UNSIGNED_BYTE & lt; & Lt; ") \ N"; // 3435973638 - What the hell is that?
int . But what else should I change ?
My class announcement and implementation:
/ * declares: * / bool read (int bytes, char * lesson); / * Implements: * / bool SocketClient :: read (int bytes, four * text) {// boost :: system :: error_code error; Four buffer = 0; Int length = 0; While (Byte> 0) {try_t len = sock.receive (boost :: asio :: buffer (and buffer, 1)); // Read a buffer with a buffer (Constant Bust :: system :: system_error and before) {std :: cout & lt; & Lt; "Socket Exception:" & lt; Ex.code () & lt; & Lt; '\ N'; return false; // When a colleague is disconnected for example}} (byteco) std :: cout & lt; & Lt; (Int) (unsigned char) buffer & lt; & Lt; ''; Bytes--; // reduce the amount to read the text [length] = buffer; Length ++; } Back true; }
unsigned int UNSIGNED_BYTE ; Probably not a name with a lot of help because I am very doubtful that the architecture you are using defines a code, which also defines a code as 8 bit signed integer it Not starting at zero and later you are writing only one part of it leaving the rest as garbage Most modern compilers / architectures have the possibility of 32/64 bits size.
socket.read (1, & ((four *) & amp; (UNSIGNED_BYTE) [0])
char and then assign it to a
int because it will with a conversion for you Au Your code portable .
Comments
Post a Comment