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 :: input array elements in c 
C :: how to delete virtual hard disk virtualbox 
C :: make a function makefile 
C :: c get current month, year, day 
C :: memcpy c 
C :: how to get the ascii value of a character in c 
C :: convert int to char in c 
C :: c read file 
C :: prime factorization of factorials using c 
C :: How to Convert double to int in C 
C :: bootstrap 4 forms 
C :: c program that replace vowels in a string with char 
C :: c check if character is an alphabet 
C :: c bubble sort 
C :: delay in c programming for windows 
C :: Installing Tailwind 
C :: how to return array of char in c 
C :: size of pointer in c 
C :: build a linked list in c 
C :: getline() in c 
C :: convert video to gif with ffmpeg 
C :: C# special character display 
C :: what is the last character of a string in c 
C :: north austin weather 
C :: fine print serial key 
C :: vscode how to output in seperate consile 
C :: main prototype 
C :: BST or NOT ?? 
C :: how to output in green in c 
C :: c++ to assembly language converter online 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =