If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
![]() |
|
|
#26 | |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
Quote:
|
|
|
|
|
|
|
#27 | |
|
Tea maker
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,379
|
Quote:
Better, though, might be Code:
#define MAX(X,Y) ( (X)>(Y) ? (X) : (Y))
....
z = MAX(x,y);
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay |
|
|
|
|
|
|
#28 |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
its more the operators in that instance I'm not used to, thus the need to think about it.
im about to try the ethatron C code juggernaut edit: cant get it to compile Code:
1>c:\projects\ethatron\ethatron\ethatron.c(14): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf' 1>c:\projects\ethatron\ethatron\ethatron.c(19): warning C4244: '+=' : conversion from 'P' to 'N', possible loss of data 1>c:\projects\ethatron\ethatron\ethatron.c(23): error C2065: 'Y' : undeclared identifier 1>c:\projects\ethatron\ethatron\ethatron.c(23): warning C4244: '=' : conversion from 'P' to 'N', possible loss of data 1>c:\projects\ethatron\ethatron\ethatron.c(23): warning C4244: '=' : conversion from 'P' to 'N', possible loss of data 1>c:\projects\ethatron\ethatron\ethatron.c(23): warning C4244: '=' : conversion from 'P' to 'N', possible loss of data 1>c:\projects\ethatron\ethatron\ethatron.c(25): warning C4244: '=' : conversion from 'P' to 'N', possible loss of data 1>c:\projects\ethatron\ethatron\ethatron.c(27): error C2065: 'Y' : undeclared identifier 1>c:\projects\ethatron\ethatron\ethatron.c(27): warning C4020: 'm' : too many actual parameters 1>c:\projects\ethatron\ethatron\ethatron.c(27): warning C4244: '=' : conversion from 'P' to 'N', possible loss of data 1>c:\projects\ethatron\ethatron\ethatron.c(28): warning C4244: 'initializing' : conversion from 'P' to 'N', possible loss of data 1>c:\projects\ethatron\ethatron\ethatron.c(28): warning C4244: '=' : conversion from 'P' to 'N', possible loss of data 1>c:\projects\ethatron\ethatron\ethatron.c(29): error C2065: 'Y' : undeclared identifier 1>c:\projects\ethatron\ethatron\ethatron.c(29): warning C4020: 'm' : too many actual parameters Last edited by itsmydamnation; 03-Aug-2012 at 12:07. |
|
|
|
|
|
#29 |
|
Member
|
From my previous post: you're invoking the C++ compiler instead of the C one. You will also have to change that 'Y' @ ln27 to something else as that is plain wrong.
|
|
|
|
|
|
#30 | |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
Quote:
edit: just tried this as well: http://msdn.microsoft.com/en-us/library/bb384838.aspx same issue when it comes to programming im much like the old homer Simpson, ignorant not stupid Last edited by itsmydamnation; 03-Aug-2012 at 12:33. |
|
|
|
|
|
|
#31 |
|
a.k.a. Ingenu
Join Date: Feb 2002
Location: Apsley, U.K.
Posts: 2,727
|
The problem with a macro is that if x or y are, say, function calls, they are evaluated more than once, so a templated function is a better option. (You can force inline it if you need to.)
__________________
So many things to do, and yet so little time to spend... |
|
|
|
|
|
#32 |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
I initialized Y but now get
Code:
1>c:\projects\ethatron\ethatron\ethatron.c(36): error C2857: '#include' statement specified with the /YcStdAfx.h command-line option was not found in the source file 1> #include"stdafx.h" now compiles |
|
|
|
|
|
#33 |
|
Heteroscedasticitate
Join Date: Mar 2005
Posts: 2,354
|
IMHO a macro is almost never better than anything if you have some other generic programming tool - in this case templates. Macros are pretty dubious in general, outside of uses like include guards or switching through debug/release builds, for example. But that's just me.
__________________
Donald Knuth: Science is what we understand well enough to explain to a computer. Art is everything else we do. |
|
|
|
|
|
#34 |
|
Heteroscedasticitate
Join Date: Mar 2005
Posts: 2,354
|
Disable precompiled header usage, StdAfx.h is VS's "nickname" for that.
__________________
Donald Knuth: Science is what we understand well enough to explain to a computer. Art is everything else we do. |
|
|
|
|
|
#35 |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
well it now looks like this
Code:
// ethatron.cpp : Defines the entrAy point for the console application.
//
#include"stdafx.h"
#include<stdlib.h>
#include<stdio.h>
#define F for(
#define D return
#define E typedef
#define V malloc(sizeof
#define Z(x)(t(0,(x-C)/y)-l+1e-6*(x-Q))
#define i m(p(r,o,v),e,d
E double P;E long N;E char*w;
N G,l,I,C,B,A,W,L,S,R,O,c,k,s=80,U=13,T=169;
P sqrt(P);
N H()
{
F;
O=scanf(" %1[#]%*[^\n]",&O);
);
scanf("%ld%*c",&O);
D O;
}
P M(N R)
{
s=s>=k?printf("%ld%c"+3*(C<1),s-k,R&7?32:10):s;
D R>0?B/2?H():getchar():R?.9+.7*M(R+1):0;
}
P t(N x,P K)
{
D x?(x>U?0:t(x+2,K)*(x-1)/x/K)+1/sqrt(K):t(2,K*K/U+1)*K;
}
N _(N J,N x)
{
F*(x?&W:&A)=W+J+x;
(O=x=W/(J=k*k))||A<J||((O=2*W/J)&&2*A/J<3);
A+=A-J+1)
{
F J*=x+O;
S--*B&&x==O;
O=x=!J)
{
s+=x+s;
M(0);
}
W+=W-J;
S+=2;
L+=L-J*k+M(S%8==B);
}
D 1;
}
P*p(P*J,P*x,P*O)
{
F R=T;R--;)O[R]=J[R]+.8*x[R];D O;
}
P
m(P*W,P*x,P s)
{
F R=U;
--R;
)
{
P*A=W+R*U;
W[R]+=s/12;
*W+=s;
*A-=*x++;
F;
A>W;
)
{
*A/=*W;
F O=R;
O;
O--)A[O]-=W[O]**A;
A-=U;
}
W+=14;
}
D*W;
}
int main(int z,w*y)
{
int Y;
N K=s,g;Y;
M(z);
s=B=C=15-H();
s=G=M(8);
s=l=M(C);
G*=g=C%3?1:3;
if(I=s=M(8))
{
N b=G+9,x=b*340+U,J=b*(l+5),*n=V(N)*J),*j=n+5*b;P*h=V(P)*x),*q=h+b,*e=q+b;
P d=K;
F;
J--;
)n[J]=J<b?0:I/2;
F;
x;
)h[--x]=0;
s=M(x);
k=256;
C=4-C;
B=C/4;
s=_(_(T,0),0);
F;--z;
)
{
R=atoi(*++y);
c=R>0?K=R,c:-2*R;
}
z=G/K+1;
z+=g>z;
I++;
c++;
F;
++J<l;
)
{
P u=0,C,y;
P*H=e+U,*o=H+b*T,*r=o-2*T,*v=r-T;
F;
x<G;
x++)
{
p(H,o-T,o);
o+=T;
H+=T;
q[x]=.7*(q[x-1]+h[x]);
}
p(H,H,r);
F;
x;
)
{
P*S=e;
w l=" !{ ,;lf6D@";j+=1-g;F;
*++l;
)
{
*S++=*j;
j+=*l%3*g-g+*l%5*b-3*b;
}
y=M(x-G);
y=M(-J)*M(-x)+M(-J-1)*y+.01;
y=sqrt((u+q[--x]+.1)/y);
o-=T;C=i)+.5;K=M(-B);
{
N f=I,Q=0;F;
f-Q>c;
)
{
P l=0;
N H=C+c/2+1;
H%=c;
H+=(f+Q+c-2*H)/2/c*c;
l=Z(Q);
O=(A-W)*Z(H)/Z(f);
_(O,R=B?K>=H:L/k>O+W);
*(R?&Q:&f)=H;
}
Q+=f;
*S=*j=Q/=2;
s=B?s:Q+k;
f=Q+n[x/z];
n[x/z]=x%z+J%(z*2/g)?f:!putc(x?l[4*g*f/z/z/I-8]:10,stderr);
H-=U;F O=156;O--;
)
{
H--;
*H=e[O%U]*e[O/U]/y+.8**H;
}
C-=Q+.5;y=i/.9)-Q-C;p(p(r+T,r,r),H,r);
h[x]=.7*h[x]+C*C;
u+=h[x];
u*=.7;
d+=C>0?-y:y;
}
}
j+=9;
}
_(_(x,x),x);
}
D 0;
}
|
|
|
|
|
|
#36 |
|
Member
Join Date: Mar 2010
Posts: 132
|
|
|
|
|
|
|
#37 | |
|
Tea maker
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,379
|
Quote:
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay |
|
|
|
|
|
|
#38 |
|
Member
Join Date: Mar 2007
Location: Wroclaw, Poland
Posts: 578
|
As for the OP - undefined behavior means exactly that: undefined behavior. Both x and y can end up with any value compiler thinks is correct (or randomizes by looking at the weather in Kuala Lumpur). On top of that compiler can do whatever it wants extra, e.g. execute printf("This code sucks");. Since this is undefined behavior it would have been perfectly valid to do it and compilers have done this in the past - GCC 1.17 would launch NetHack or Rogue upon discovering undefined behavior in the code. Trying to reason "this should be X" or "why do I get Y" is absolutely pointless.
__________________
Shifty Geezer: I don't think the guy really understands the subject. PARANOiA: To be honest, Shifty, what you've described is 95% of Beyond3D - armchair experts spouting fact based on the low-level knowledge of a few. This posting is provided "AS IS" with no warranties, and confers no rights. |
|
|
|
|
|
#39 |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
had a go at the start of grey-scale image compressor ( did you write this code Ethatron?). Pretty hard with kids about and the logic of some of the macro's is beyond me
Code:
// replace F with for(
#define F for(
// replace D with return
#define D return
//replace E with typedef
#define E typedef
// replace V with malloc(sizeof
// malloc is used to request/allocate a block of memory sized in bytes, block isn't initalized
#define V malloc(sizeof
// a macro that i cant figure out how to read it
#define Z(x)(t(0,(x-C)/y)-l+1e-6*(x-Q))
// another marco of stuff..lol
#define i m(p(r,o,v),e,d
//use typedef to create aliases fp double = P, long in = N , 1byte char = *w
E double P;
E long N;
E char*w;
//all of these are long ints
N G,l,I,C,B,A,W,L,S,R,O,c,k,s=80,U=13,T=169;
// returns square root, cant see the point in it yet still builds when i comment it out :)
P sqrt(P);
//fuction called H
N H()
{
// FOR (
F;
// takes input data dont understand the paramaters
// & is bitwise AND , seems to care about the data last
// time fuction was ran, output is O and O is used within the function
O=scanf(" %1[#]%*[^\n]",&O);
);
scanf("%ld%*c",&O);
//returns O
D O;
|
|
|
|
|
|
#40 |
|
Member
Join Date: Mar 2010
Posts: 132
|
|
|
|
|
|
|
#41 |
|
Darlek ******
Join Date: Jun 2004
Posts: 9,489
|
I was under the impression C++ was an extension of C and that a C++ compiler could compile programs written in C
__________________
Guardian of the Most holy Two Terabytes of Gaming Goodness™ |
|
|
|
|
|
#42 |
|
a.k.a. Ingenu
Join Date: Feb 2002
Location: Apsley, U.K.
Posts: 2,727
|
Your impression is mostly correct.
C++ compilers have historically just been patched up C compilers, which explains why many C++ features took ages to get integrated (and spec compliant.).
__________________
So many things to do, and yet so little time to spend... |
|
|
|
|
|
#43 |
|
Darlek ******
Join Date: Jun 2004
Posts: 9,489
|
Mostly, but the op couldnt compile the C code with his C++ compiler and had to use a C compiler
And if I was correct and C++ compilers did compile C why would C compilers (made post C++ introduction) exist
__________________
Guardian of the Most holy Two Terabytes of Gaming Goodness™ |
|
|
|
|
|
#44 | |
|
Member
Join Date: Jan 2010
Posts: 375
|
Quote:
No, it's from Bernie Meyer. He was participating in a smallest code contest, that's why there is the macro code-implosion in it. He was also playing with image compression at the time, which he took to try himself in the contest. For quite some time this was the most efficient lossless image compressor available. To me it's the most perfect source I've ever seen, it's funny (in various ways), it's artistic, it's efficient, it's marvelous (you ran it once? a possible commandline is like this: "program <input.pgm >output.coded"), it's also playful ironic (sarkastic) in regards to I-have-the-new-better-algorithm science. Like the eggs from Kinderüberraschung. The variables give away its name if you want to search for it. "P sqrt(P)" is a protoype BTW, no need to include math.h "& is bitwise AND" is wrong, & is the get-reference-of-variable operator. In C that's about it (and reference means pointer), in C++ you can also declare variables to be references instead of containers (and they are distinct types). I think actually that would be a good start for learning a pure C++ syntax/concept. And if you learn that first you may not get the bad habit of using pointers all the time, it nicely goes with operator overloading as well, which I would recommend next. All the other stuff you've shown is the same in C (?: is called ternary operator, ++ increment and -- decrement also are part of C), and a lot of other languages. |
|
|
|
|
|
|
#45 |
|
Moderator
Join Date: Feb 2002
Location: Taiwan
Posts: 2,347
|
Although most C programs are valid C++ programs, not all C programs are valid C++ programs. The most obvious examples are those with variable names that happens to be C++ keywords (that also influences the choice of C++ keyword names).
|
|
|
|
|
|
#46 | |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
Quote:
what im actually trying to do is print decimal values as binary using _itoa_s in stdlib.h. I have it working but i dont understand why it is working if i have code like this Code:
void bit_shift()
{
using namespace std;
clearscreen();
int dec_number = 0;
cout << " showing how bit shift works " << endl ;
cout << "please enter an integer number :";
cin >> dec_number ;
char *binary_value=0;
//returns ptr to array
binary_value = binary_conversion (dec_number);
std::cout << &binary_value << endl;
}
char *binary_conversion(int i)
{
//char *buffer_return = new char[33];
static char buffer[33];
_itoa_s (i,buffer,2);
//std::cout << buffer_return ;
return buffer;
}
but if i change that to std::cout << &binary_value[0] << endl; i get the contents of the entire array (the desired result) but i dont understand why . if i change it to std::cout << *binary_value << endl; i just get the first element of the array ( unless 0 it will always be 1) i tried something like Code:
for ( int i =0 ; i < 34 ; i++)
{
std::cout << *binary_value[i] << endl
}
|
|
|
|
|
|
|
#47 |
|
Darlek ******
Join Date: Jun 2004
Posts: 9,489
|
try
#include <iostream> #include <string> #include <cmath> int main() { std::string binary; double decimal = 0; std::cout << "Enter the binary value you wish to convert into decimal: " << endl; std::cin >> binary; for(int counter = 0; counter < binary.size(); counter++) if(binary.c_str()[counter] == '1') decimal += pow(2, counter); cout << "The decimal representation of the given binary is: " << decimal << endl; return 0; } edit: may be missing std::endl std::cout
__________________
Guardian of the Most holy Two Terabytes of Gaming Goodness™ |
|
|
|
|
|
#48 | |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
cheers
but my code works fine: output: Quote:
its more i don't understand why &binary_value[0] returns the entire array when &binary_value returns a memory address and *binary_value returns a single element of the array |
|
|
|
|
|
|
#49 |
|
Moderator
Join Date: Feb 2002
Location: Taiwan
Posts: 2,347
|
That's because &binary_value[0] is a char* type, which is treated as a string in C. On the other hand, *binary_value is a char type, so it's a simple value.
|
|
|
|
|
|
#50 |
|
Member
Join Date: Apr 2007
Location: Australia
Posts: 645
|
Well i spend the last two nights before bed working pretty much on this...
At first i thought it would be cool. Now i am never doing anything as stupid pointless and insane again ; heres the code Code:
void OR_XOR()
{
using namespace std;
int dec_number_1 = 0;
cout << " showing how XOR, OR and AND works " << endl ;
cout << "please enter an integer number :";
cin >> dec_number_1 ;
int dec_number_2 = 0;
cout << "please enter a second integer number :" ;
cin >> dec_number_2 ;
cout << endl << endl <<endl ;
//libary fuction to convert dec number into binary for first number
char buffer_1[33];
_itoa_s (dec_number_1,buffer_1,2);
//counts the number of binary digits with the array,
//aka elements with either 1 or 0 in them
int count_1= 0;
for each (char i in buffer_1)
{
//std::cout << i ;
if (i ==48 || i ==49) {
count_1++ ;
}
}
//libary fuction to convert dec number into binary for second number
char buffer_2[33];
_itoa_s (dec_number_2,buffer_2,2);
//counts the number of binary digits with the array,
//aka elements with either 1 or 0 in them
int count_2=0;
for each (char j in buffer_2)
{
if (j ==48 || j==49)
{
count_2++;
}
}
// used to figure out which "number" is longer in binary length
// positive number = first is longer, neg number second is longer
int bit_length_difference=0;
bit_length_difference = count_1 - count_2;
int XOR_count =0;
int OR_count =0;
int AND_count=0;
if ( count_1 > count_2)
{
XOR_count =count_1;
OR_count =count_1;
AND_count=count_1;
}
else
{
XOR_count =count_2;
OR_count =count_2;
AND_count=count_2;
}
// final array for first number converted from char to int and will be
// same binary lenth as second_number_final
int first_number_final[33];
int second_number_final[33];
int XOR_array[33];
int XOR_DEC_value=0;
int OR_array[33];
int OR_DEC_value=0;
int AND_array[33];
int AND_DEC_value=0;
//used as a counter for first_number_final an second_number_final array
int count_fnf=0;
int count_snf=0;
//if b_l_d is less then 0 then second number is longer in binary digits then first
// create a new array and populate its lowest elements with int 0 until addition 0's plus buffer_1 binary length is
// the same as buffer_2.
if ( bit_length_difference < 0)
{
//adds the value 0 to elements in first_number_final until
// bit_length_difference = 0;
while ( bit_length_difference != 0)
{
first_number_final[count_fnf] = 0;
bit_length_difference++;
count_fnf++;
}
//used in whileloop to track elements in buffer_1
int i = 0;
while ( count_1 != 0)
{
//if char element in buffer array ==48 (int 0) then add to first_number_final array
// in element number tracked by int var temp.
// int i tracks buffer_1 element position
if (buffer_1[i] == 48)
{
first_number_final[count_fnf]=0;
i++;
count_fnf++;
count_1--;
}
// if char element ==49 (int 1) then add to first_number_final array
if (buffer_1[i] == 49)
{
first_number_final[count_fnf]=1;
i++;
count_fnf++;
count_1--;
}
}
//used in whileloop to track elements in buffer_2
int k = 0;
//used to convert the second number to binary
while ( count_2 != 0)
{
//if char element in buffer array ==48 (int 0) then add to first_number_final array
// in element number tracked by int var temp.
// int i tracks buffer_1 element position
if (buffer_2[k] == 48)
{
second_number_final[count_snf]=0;
k++;
count_snf++;
count_2--;
}
// if char element ==49 (int 1) then add to first_number_final array
if (buffer_2[k] == 49)
{
second_number_final[count_snf]=1;
k++;
count_snf++;
count_2--;
}
}
}else if (bit_length_difference > 0)
{
//adds the value 0 to elements in second_number_final until
// bit_length_difference = 0;
while ( bit_length_difference != 0)
{
second_number_final[count_snf] = 0;
bit_length_difference--;
count_snf++;
}
//used in whileloop to track elements in buffer_1
int i = 0;
while ( count_2 != 0)
{
//if char element in buffer array ==48 (int 0) then add to first_number_final array
// in element number tracked by int var temp.
// int i tracks buffer_1 element position
if (buffer_2[i] == 48)
{
second_number_final[count_snf]=0;
i++;
count_snf++;
count_2--;
}
// if char element ==49 (int 1) then add to first_number_final array
if (buffer_2[i] == 49)
{
second_number_final[count_snf]=1;
i++;
count_snf++;
count_2--;
}
}
//used in whileloop to track elements in buffer_1
int k = 0;
//used to convert the second number to binary
while ( count_1 != 0)
{
//if char element in buffer array ==48 (int 0) then add to first_number_final array
// in element number tracked by int var temp.
// int i tracks buffer_1 element position
if (buffer_1[k] == 48)
{
first_number_final[count_fnf]=0;
k++;
count_fnf++;
count_1--;
}
// if char element ==49 (int 1) then add to first_number_final array
if (buffer_1[k] == 49)
{
first_number_final[count_fnf]=1;
k++;
count_fnf++;
count_1--;
}
}
//both values have same binary lenght
}
else
{
//used in whileloop to track elements in buffer_1 and buffer_2 as they are the same length
int k = 0;
//used to convert the second number to binary
while ( count_1 != 0)
{
//if char element in buffer array ==48 (int 0) then add to first_number_final array
// in element number tracked by int var temp.
// int i tracks buffer_1 element position
if (buffer_1[k] == 48)
{
first_number_final[count_fnf]=0;
count_fnf++;
count_1--;
std::cout << count_fnf;
}
// if char element ==49 (int 1) then add to first_number_final array
if (buffer_1[k] == 49)
{
first_number_final[count_fnf]=1;
count_fnf++;
count_1--;
std::cout << count_fnf;
}
if (buffer_2[k] == 48)
{
second_number_final[count_snf]=0;
count_snf++;
std::cout << count_snf << std::endl;
}
// if char element ==49 (int 1) then add to first_number_final array
if (buffer_2[k] == 49)
{
second_number_final[count_snf]=1;
count_snf++;
std::cout << count_snf << std::endl;
}
k++;
}
}
std::cout << " the first number you entered in binary is : \t \t " ;
int i=0;
while (i != count_fnf)
{
std::cout << first_number_final[i] ;
i++;
}
std::cout << std::endl;
std::cout << " the second number you entered in binary is : \t \t " ;
int k=0;
while (k != count_snf)
{
std::cout << second_number_final[k] ;
k++;
}
std::cout << std::endl;
int j =0;
int power = XOR_count -1;
int power_temp = 0;
float power_of_2 = 2;
while (j != XOR_count)
{
XOR_array[j] = first_number_final[j] ^ second_number_final[j];
if ( XOR_array[j] == 1)
{
if ( j == (count_fnf-1))
{
XOR_DEC_value = XOR_DEC_value + 1;
}
else
{
double power_temp =pow(power_of_2,power);
XOR_DEC_value = XOR_DEC_value + power_temp ;
}
}
power--;
j++;
}
std::cout << "XOR'd number based off your numbers in binary is : \t " ;
int l=0;
while (l != XOR_count)
{
std::cout << XOR_array[l] ;
l++;
}
std::cout << std::endl;
std::cout << "the dec value of the XOR number is : \t \t \t " << XOR_DEC_value << std::endl;
int M =0;
int power_OR = OR_count -1;
int power_OR_temp = 0;
while (M != OR_count)
{
OR_array[M] = first_number_final[M] | second_number_final[M];
if ( OR_array[M] == 1)
{
if ( M == (count_fnf-1))
{
OR_DEC_value = OR_DEC_value + 1;
}
else
{
double power_OR_temp =pow(power_of_2,power_OR);
OR_DEC_value = OR_DEC_value + power_OR_temp ;
}
}
power_OR--;
M++;
}
std::cout << "OR'd number based off your numbers in binary is : \t " ;
int N=0;
while (N != XOR_count)
{
std::cout << OR_array[N] ;
N++;
}
std::cout << std::endl;
std::cout << "the dec value of the OR number is : \t \t \t " << OR_DEC_value << std::endl;
int O =0;
int power_AND = AND_count -1;
int power_AND_temp = 0;
while (O != OR_count)
{
AND_array[O] = first_number_final[O] & second_number_final[O];
if ( AND_array[O] == 1)
{
if ( O == (count_fnf-1))
{
AND_DEC_value = AND_DEC_value + 1;
}
else
{
double power_AND_temp =pow(power_of_2,power_AND);
AND_DEC_value = AND_DEC_value + power_AND_temp ;
}
}
power_AND--;
O++;
}
std::cout << "AND'd number based off your numbers in binary is : \t " ;
int P=0;
while (P != AND_count)
{
std::cout << AND_array[P] ;
P++;
}
std::cout << std::endl;
std::cout << "the dec value of the AND number is : \t \t \t " << AND_DEC_value << std::endl;
std::cout << std::endl << std::endl << std::endl << std::endl << std::endl;
}
Code:
showing how XOR, OR and AND works please enter an integer number :1243 please enter a second integer number :123 the first number you entered in binary is : 10011011011 the second number you entered in binary is : 00001111011 XOR'd number based off your numbers in binary is : 10010100000 the dec value of the XOR number is : 1184 OR'd number based off your numbers in binary is : 10011111011 the dec value of the OR number is : 1275 AND'd number based off your numbers in binary is : 00001011011 the dec value of the AND number is : 91 Now its 1:00am and time for bed..... work in 7 hours Last edited by itsmydamnation; 07-Aug-2012 at 16:04. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|