www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/18/23:48:03

From: "matthew p. conte" <spam AT somebody DOT else>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Binary << ?
Date: Wed, 18 Mar 1998 16:37:03 -0500
Organization: little, if any
Lines: 23
Message-ID: <6epegv$pi0@dfw-ixnews3.ix.netcom.com>
References: <01bd5261$69dc6a00$4a3e64c2 AT default>
Reply-To: "matthew p. conte" <dont AT bother DOT com>
NNTP-Posting-Host: alb-ny6-58.ix.netcom.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

laine wrote:
>Can someone tell me how the binary << work?

All kinds of off topic, but...

<< and >> are the binary shift operators.  They shift the bits in a variable
or a number representation...

If you had an unsigned char b = 4; the bits look like this:
0 0 0 0 0 1 0 0
and you did a shift to the left by 1:
b = b<<1;  (or even better b<<=1)
the bits would now be:
0 0 0 0 1 0 0 0
making b = 8.  So just imagine that bitshifts to the left are multiplying by
powers of 2, and those to the right are dividing by powers of 2.  So:

b >>= 3;  is dividing by 2^3 or 8.

Good luck,
Matt.


- Raw text -


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