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

  1. What is the time complexity of this code?
    Kindly tell me. Thanks

    ReplyDelete
    Replies
    1. Its time complexity is constant i.e. O(1)

      Delete
  2. Kindly tell me whats the loop invariant

    ReplyDelete

Recent Posts