Wednesday, 3 February 2016

Byte Ordering | Bytes In order (Computer Networks)

Byte Ordering | Bytes In order (Computer Networks)

Description:    The following C program to find out the host byte ordering of a machine/computer.
C has a datatype short. It takes 2 bytes. We can store some data in short datatype and read memory byte wise

C Code

#include<stdio.h>
#include<unistd.h>

int main(){

   short a=500;
   unsigned char* p = (char *)&a;
  
   printf("\nActual Value: %i\n",a);
   printf("\nAt First Byte: %i\n",*(p+0));
   printf("At Second Byte: %i\n\n",*(p+1));
}


4 comments

Post a Comment

Recent Posts