Search
 
SCRIPT & CODE EXAMPLE
 

C

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 
",port);

  return 0;
}
Comment

2 bytes integer c

[8-bit] signed char: -127 to 127
 [8-bit] unsigned char: 0 to 255
 [16-bit]signed short: -32767 to 32767
 [16-bit]unsigned short: 0 to 65535
 [32-bit]signed long: -2147483647 to 2147483647
 [32-bit]unsigned long: 0 to 4294967295
 [64-bit]signed long long: -9223372036854775807 to 9223372036854775807
 [64-bit]unsigned long long: 0 to 18446744073709551615
Comment

PREVIOUS NEXT
Code Example
C :: execute maven project in cmd 
C :: C percentage program 
C :: get time to complete code c 
C :: dynamically create matrix c 
C :: clrscr in c 
C :: dart in android studio 
C :: c programming itoa() example 
C :: create empty vector in rust 
C :: c output 
C :: how to print value of pointer in c 
C :: addition in c 
C :: fractional knapsack problem in c 
C :: vbnet create and write on file 
C :: c modify char array 
C :: go Iterating over an array using a range operator 
C :: c float 
C :: C Passing Pointers to Functions 
C :: fgets remove newline 
C :: equal string c 
C :: simple bootstrap form example 
C :: malloc basics 
C :: check whether a number is prime or not in c 
C :: C - program to create 1D array 
C :: Complete the function in the editor. It has one parameter: an array, . It must iterate through the array performing one of the following actions on each element: 
C :: do while loop in c 
C :: print 100 times c 
C :: function that changes all lowercase letters of a string to uppercase. 
C :: string in c 
C :: c malloc 
C :: how to declare an array of n numbers in c 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =