www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/19/20:39:40

From: Inkel AT sion DOT com
To: djgpp AT delorie DOT com
Date: 19 Mar 1998 22:35:10 EDT
Subject: Binary << ?
Message-ID: <0d3dc3741011438PROXY@sion.net>

LA>Hi!

LA>Can someone tell me how the binary << work?

LA>Thanks,
LA>Jarkko Laine

LA>www: http://members.tripod.com/~Jakero
LA>e-mail: Jarkko DOT Laine AT ks DOT iwn DOT fi

The binary << work is very simple. For example, you have this:

#include <stdio.h>

int main(int argc, char *argv[] {
 char test=1; /* test binary value = 00000001 */
 printf("Test value is : %d",test); /* test = 1 (in decimal notation) */
 test = test << 1; /* this shift left 1 position the bits of test */
                   /* so the binary value of test now it's = 00000010 */
 printf("Test value is : %d",test); /* test = 2 (in decimal notation) */
 test = test << 3; /* new test binary value = 00010000 */
 printf("Test value is : %d",test); /* test = 16 */
 return 0;
}

So whe can say that:

   1.) The binary << shift the bits of a expresison X places to left,
         where X is the amount of places you want the expression to be
    shifted.
   2.) When we shift left some bit, what we really are doing is to
    multiply the given expression for 2^X (2 at thw power of X),
         i.e.:
            2 << 2 = 2 * 2^2 = 2 * 4 = 8
   3.) The binary >> do the same that << but shift the bits to right, so
         whe now are dividing by 2 at the power of X, i.e.:
            8 >> 2 = 8 / 2^2 = 8 / 4 = 2

I hope this would help, if don't, please let me know n' I'll try to be
more especific. Good luck,

Leandro M. "Spawn" López (mailto:inkel AT sion DOT com)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019