446,234 Members | 1,872 Online
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

 P: n/a Hi All, Sorry if I am calling expert's advice on such a simple thing. I am reading a c++ code but do not understand what this means? #define DM_ITEMS 6 #define FM_ITEMS ( 1 << (DM_ITEMS - 1) ) when I look at the value of FM_ITEMS in my debug log it is 32. How in the heven it comes up with that number? It will be really nice to get a handle on this puzzle. Thanks you in advance. J. Jul 19 '05 #1
7 Replies

 P: n/a John Smith wrote: Sorry if I am calling expert's advice on such a simple thing. I am reading a C++ code but do not understand what this means? #define DM_ITEMS 6 #define FM_ITEMS ( 1 << (DM_ITEMS - 1) ) when I look at the value of FM_ITEMS in my debug log it is 32. How in the heaven it comes up with that number? (1 << (DM_ITEMS - 1)) = (1 << (6 - 1)) = (1 << 5) = 1*pow(2, 5) = 1*32 Jul 19 '05 #2

 P: n/a "John Smith" wrote in message news:bh***********@madmax.keyway.net Hi All, Sorry if I am calling expert's advice on such a simple thing. I am reading a c++ code but do not understand what this means? #define DM_ITEMS 6 #define FM_ITEMS ( 1 << (DM_ITEMS - 1) ) when I look at the value of FM_ITEMS in my debug log it is 32. How in the heven it comes up with that number? It will be really nice to get a handle on this puzzle. Thanks you in advance. J. << is the left shift operator. x<

 P: n/a "Matt" wrote in message news:vj************@corp.supernews.com "Quixote" wrote in message news:3f********@news.brisbane.pipenetworks.com... << is the left shift operator. x<

 P: n/a Hi Matt. I am writting an OCX control, and a vb app for a computer telephony application. I need to map the hardware return values which are defined in the c++ header file, to constants in my VB app. I managed to cover most of them but this one got me puzzled. Here are a few lines from my .H file: #define DE_RINGS 1 /* Rings received */ #define DE_SILON 2 /* Silence on */ #define DE_SILOF 3 /* Silenec off */ .. .. .. #define DM_RINGS ( 1 << (DE_RINGS - 1) ) #define DM_SILON ( 1 << (DE_SILON - 1) ) #define DM_SILOF ( 1 << (DE_SILOF - 1) ) In this ( << ) shift operation I do not see how it could rais any number by any power. However, I setup some logging and this is what I got: DE_SILOF=3, DM_SILOF=4 DE_LCOF=5, DM_LCOF=16 DE_WINK=6, DM_WINK=32 DE_DIGOFF=9, DM_DIGOFF=256 You are right it is raising 2 by the power of DE_XXXX values, but I just don't see how. I really appreciate your time. John. "Matt" wrote in message news:vj************@corp.supernews.com... "Quixote" wrote in message news:3f********@news.brisbane.pipenetworks.com... "John Smith" wrote in message news:bh***********@madmax.keyway.net Hi All, Sorry if I am calling expert's advice on such a simple thing. I am reading a c++ code but do not understand what this means? #define DM_ITEMS 6 #define FM_ITEMS ( 1 << (DM_ITEMS - 1) ) when I look at the value of FM_ITEMS in my debug log it is 32. How in the heven it comes up with that number? It will be really nice to get a handle on this puzzle. Thanks you in advance. J. << is the left shift operator. x<

 P: n/a Hi "John Smith" wrote in message news:bh**********@madmax.keyway.net... In this ( << ) shift operation I do not see how it could rais any number by any power. However, I setup some logging and this is what I got: DE_SILOF=3, DM_SILOF=4 DE_LCOF=5, DM_LCOF=16 DE_WINK=6, DM_WINK=32 DE_DIGOFF=9, DM_DIGOFF=256 You are right it is raising 2 by the power of DE_XXXX values, but I just don't see how. Matt has explained it very nicely below. If you still have trouble, get a book on binary arithmetic. "Matt" wrote in message news:vj************@corp.supernews.com... "Quixote" wrote in message news:3f********@news.brisbane.pipenetworks.com... "John Smith" wrote in message news:bh***********@madmax.keyway.net > Hi All, > > Sorry if I am calling expert's advice on such a simple thing. I am > reading a c++ code but do not understand what this means? > > #define DM_ITEMS 6 > #define FM_ITEMS ( 1 << (DM_ITEMS - 1) ) > > when I look at the value of FM_ITEMS in my debug log it is 32. > > How in the heven it comes up with that number? > > It will be really nice to get a handle on this puzzle. > > Thanks you in advance. > > J. << is the left shift operator. x<