
November 5th, 2013, 02:34 PM
#1
how calculating values from '' results?
see these result:
Code:
int c=10, b=20;
int a = c  b;
i don't know what a will get... can anyone explain to me?
now imagine that i only have the a result. how can i get the c and b?
(maybe knowing these, can fix 1 problem )

November 5th, 2013, 02:48 PM
#2
Re: how calculating values from '' results?
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it.  P. D. Ouspensky

November 5th, 2013, 03:10 PM
#3
Re: how calculating values from '' results?
Originally Posted by D_Drmmr
like i read before....
i need convert the 10 and 20 to binary and then i do the math
10 = 1010 in binary
20 = 10100 in binary
1010  10100 = 10100 = 20
tell me if it's corrected

November 5th, 2013, 03:29 PM
#4
Re: how calculating values from '' results?
 is the bitwise or operator. The corresponding bit in the result will be turned on if the bit is turned on in either of the operands.
01010 
10100 =
11110
Last edited by GCDEF; November 5th, 2013 at 03:33 PM.

November 5th, 2013, 03:33 PM
#5
Re: how calculating values from '' results?
Originally Posted by GCDEF
 is the logical or operator. The corresponding bit in the result will be turned on if the bit is turned on in either of the operands.
01010 
10100 =
11110
and i see my mistake: you put '0' on left. thanks for correct me.
now heres the question that i don't know: now from 30 (=11110), imagine that i need the value 01010(=10). how can i get it?

November 5th, 2013, 03:39 PM
#6
Re: how calculating values from '' results?
Follow the link D_Drmmr provided and look at XOR

November 5th, 2013, 04:08 PM
#7
Re: how calculating values from '' results?
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C, C++ Compiler: Microsoft VS2017

November 5th, 2013, 04:17 PM
#8
Re: how calculating values from '' results?
(someone forget telling us, in tutorials, that we must convert the values to binary for use the bitwise operators... was my 1st confusion... you can see from the thread begining)
or ()  if 1 or both operators are '1', the result is '1'... else is '0';
xor (^)  if 1 of operators are '1' then the result is '1'. if both operators are the same, the result is '0'.
11110
10100 ^
_______
01010 = 10
11110
01010 ^
________
10100 = 20
ok... now i understand.... i have some problem convert from decimal to binary... can anyone explain, please?
i continue with 1 question:
the csbi.wAttributes is a combination of several '': some for backcolor and others for textcolor. but why csbi.wAttributes & 0xff0f for calculate the textcolor and (csbi.wAttributes & 0xfff0) >> 4 for calculate the backcolor?
can anyone explain to me, please?
Last edited by Cambalinho; November 5th, 2013 at 04:29 PM.

November 5th, 2013, 04:31 PM
#9
Re: how calculating values from '' results?
i have some problem convert from decimal to binary... can anyone explain, please?
If you want to just display the binary equivalent of a decimal number then have a look at
http://programmingknowledgeblog.blog...cimalsto.html
If you want to convert a decimal number to a character string, this can be done using _itoa (or better using _itoa_s)
http://msdn.microsoft.com/enus/libr.../yakksftt.aspx
http://msdn.microsoft.com/enus/libr.../0we9x30h.aspx
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
char bin[100];
long dec;
cout << "Enter the decimal to be converted:";
cin >> dec;
_itoa(dec, bin, 2);
cout << bin;
return 0;
}
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C, C++ Compiler: Microsoft VS2017

November 5th, 2013, 04:40 PM
#10
Re: how calculating values from '' results?
Originally Posted by 2kaud
thanks for all... thanks
(see if you can explain to me that calculation, please)

November 5th, 2013, 04:40 PM
#11
Re: how calculating values from '' results?
Originally Posted by Cambalinho
now from 30 (=11110), imagine that i need the value 01010(=10). how can i get it?
I don't think that's possible since OR doesn't have an inverse. Say you do x OR y and get z. The truth table looks like this,
x OR y = z

0 0 0
0 1 1
1 0 1
1 1 1
These are all possibilities of x OR'ed with y giving z.
What you're asking for is some operation between y and z that would give x back. Basically you're asking for this truth table,
x = y ? z

0 0 0
0 1 1 (*)
1 0 1
1 1 1 (*)
But that's not possible due to the two lines marked with (*). When y and z are both 1 you don't know whether x is supposed to be 0 or 1. So the hypothetical ? operation that would be an inverse to OR doesn't exist.

November 5th, 2013, 04:44 PM
#12
Re: how calculating values from '' results?
csbi.wAttributes & 0xff0f for calculate the textcolor and (csbi.wAttributes & 0xfff0) >> 4 for calculate the backcolor?
can anyone explain to me, please?
You haven't posted the code containing these statements, but the foreground colors are defined by the first 4 bits (0 3) and the background colour by the next 4 bits (4  7). Considering this as binary (most signifiant on left) we have bbbbffff and as hex 0xbf where b is background and f is foreground. So to just get the foreground colour use & 0x0f which gives the least significant 4 bits (ie the foregound). To get the background use 0xf0 >> 4 which shifts the 4 bit background colour in bits 4  7 right 4 bits which puts them in bits 0  3 and so can be treated as a colour in the range 0  15.
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C, C++ Compiler: Microsoft VS2017

November 5th, 2013, 04:47 PM
#13
Re: how calculating values from '' results?
Originally Posted by 2kaud
You haven't posted the code containing these statements, but the foreground colors are defined by the first 4 bits (0 3) and the background colour by the next 4 bits (4  7). Considering this as binary (most signifiant on left) we have bbbbffff and as hex 0xbf where b is background and f is foreground. So to just get the foreground colour use & 0x0f which gives the least significant 4 bits (ie the foregound). To get the background use 0xf0 >> 4 which shifts the 4 bit background colour in bits 4  7 right 4 bits which puts them in bits 0  3 and so can be treated as a colour in the range 0  15.
sorry, what means '0xfff0'?

November 5th, 2013, 04:56 PM
#14
Re: how calculating values from '' results?
A number starting 0x means a hexadecimal number (a number system using base 16). The digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f where a b c d e f mean 10, 11, 12, 13, 14, 15 respectfully.
In the program posted in post #9, change the 2 in the _itoa line to 16 and it will convert decinal numbers to base 16 (hex). When working with some types of numbers where different bits have special meanings, hexadecimal notation is often used rather than decimal as the bit patterns can be more clearly identified.
See
http://www.cplusplus.com/doc/hex/
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C, C++ Compiler: Microsoft VS2017
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
This a Codeguru.com survey!
