Horje
two bytes to int c Code Example
two bytes to int c
// bytes_to_int_example.cpp
// Output: port = 514

// I am assuming that the bytes the bytes need to be treated as 0-255 and combined MSB -> LSB

// This creates a macro in your code that does the conversion and can be tweaked as necessary
#define bytes_to_u16(MSB,LSB) (((unsigned int) ((unsigned char) MSB)) & 255)<<8 | (((unsigned char) LSB)&255) 
// Note: #define statements do not typically have semi-colons
#include <stdio.h>

int main()
{
  char buf[2];
  // Fill buf with example numbers
  buf[0]=2; // (Least significant byte)
  buf[1]=2; // (Most significant byte)
  // If endian is other way around swap bytes!

  unsigned int port=bytes_to_u16(buf[1],buf[0]);

  printf("port = %u \n",port);

  return 0;
}




C

Related
lerp function c Code Example lerp function c Code Example
convert string to float c Code Example convert string to float c Code Example
https://www.codegrepper.com/search.php?q=convert%20string%20to%20float%20c Code Example https://www.codegrepper.com/search.php?q=convert%20string%20to%20float%20c Code Example
rename c Code Example rename c Code Example
create empty vector in rust Code Example create empty vector in rust Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12