本文整理汇总了C++中xor函数的典型用法代码示例。如果您正苦于以下问题:C++ xor函数的具体用法?C++ xor怎么用?C++ xor使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: X64
X64() : CodeGenerator(true)
{
prologue(0);
static __int64 x;
// Simple operations
mov(r10, r11);
mov(r0, r1);
mov(r0d, r1d);
mov(r0b, r1b);
xor(rax, rax);
xor(rbx, rbx);
mov(qword_ptr [&x+rax+4*rbx], 1);
mov(qword_ptr [&x], 2); // RIP-relative addressing
push(r14);
pop(r14);
const char *string = "Good luck with your 64-bit processor!";
mov(rcx, (unsigned int)string);
call((unsigned int)printf);
epilogue();
}
示例2: includeError2
void
includeError2 (char *string, int size)
{
int i = 0;
int exponent = 0;
unsigned char mask = '\0';
for (i = 0; i < size; i++)
{
if (drand48 () < ERROR_RATE)
{
exponent = floor (drand48 () * 16);
if (exponent < 8)
{
mask = 1 << exponent;
string[i] = xor (string[i], mask);
}
else
{
mask = 1 << (exponent - 8);
string[i + 1] = xor (string[i + 1], mask);
}
}
}
return;
}
示例3: main
/* Driver program to test above functions */
int main()
{
int T = 0;
int n[10] = {0};
//int n = 4;
int res = 0 ,first = 1 ;
scanf("%d",&T);
for(int j=0;j<T;j++){
scanf("%d",&n[j]);
for(int i=0;i<n[j];i++) {
scanf("%d",&arr[j][i]);
}
}
for(int k=0;k<T;k++) {
res = 0; first = 1;
for(int j=1;j<=n[k];j++) {
for(int i=1;i<=(n[k]-j)+1;i++)
{
if(first) {
res = xor(i,j,k); first = 0 ;continue;
}
res = res ^ xor(i,j,k);
}
}
printf("%d\n",res);
}
return 0;
}
示例4: crypto_cbc_decrypt_inplace
static int crypto_cbc_decrypt_inplace(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm,
void (*xor)(u8 *, const u8 *,
unsigned int))
{
void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_decrypt;
int bsize = crypto_cipher_blocksize(tfm);
unsigned long alignmask = crypto_cipher_alignmask(tfm);
unsigned int nbytes = walk->nbytes;
u8 *src = walk->src.virt.addr;
u8 stack[bsize + alignmask];
u8 *first_iv = (u8 *)ALIGN((unsigned long)stack, alignmask + 1);
memcpy(first_iv, walk->iv, bsize);
/* Start of the last block. */
src += nbytes - nbytes % bsize - bsize;
memcpy(walk->iv, src, bsize);
for (;;) {
fn(crypto_cipher_tfm(tfm), src, src);
if ((nbytes -= bsize) < bsize)
break;
xor(src, src - bsize, bsize);
src -= bsize;
}
xor(src, first_iv, bsize);
return nbytes;
}
示例5: xor
long long int xor(long long int a[],long long int i,long long int ans)
{
if(i<0)
return ans;
else
return max(xor(a,i-1,ans),xor(a,i-1,ans^a[i]));
}
示例6: cts_dec
static void
cts_dec (unsigned char *out, unsigned char *in, unsigned char *iv,
unsigned int len)
{
int r;
unsigned int len2;
unsigned char pn1[B], pn[B], cn[B], cn1[B];
if (len < B + 1) abort ();
len2 = (len - B - 1) & ~(B-1);
cbc_dec (out, in, iv, len2);
out += len2;
in += len2;
len -= len2;
if (len2)
iv = in - B;
if (len <= B || len > 2 * B)
abort ();
memcpy (cn1, in, B);
r = camellia_dec_blk (cn1, pn, &dctx);
if (!r) fprintf(stderr, "error, line %d\n", __LINE__), exit(1);
memset (cn, 0, sizeof(cn));
memcpy (cn, in+B, len-B);
xor (pn, pn, cn);
memcpy (cn+len-B, pn+len-B, 2*B-len);
r = camellia_dec_blk (cn, pn1, &dctx);
if (!r) fprintf(stderr, "error, line %d\n", __LINE__), exit(1);
xor (pn1, pn1, iv);
memcpy(out, pn1, B);
memcpy(out+B, pn, len-B);
}
示例7: fullAdder
void fullAdder (char a, char b, char ci, char & co, char & sum)
{
char axb, ab, abc;
axb = xor (a, b);
ab = and (a, b);
abc = and (axb, ci);
co = or (ab, abc);
sum = xor (axb, ci);
}
示例8: switch
void GSDrawScanlineCodeGenerator::WritePixel(const Xmm& src, const Xmm& temp, const Reg32& addr, uint8 i, int psm)
{
static const int offsets[4] = {0, 2, 8, 10};
Address dst = ptr[addr * 2 + (size_t)m_env.vm + offsets[i] * 2];
if(m_cpu.has(util::Cpu::tSSE41))
{
switch(psm)
{
case 0:
if(i == 0) movd(dst, src);
else pextrd(dst, src, i);
break;
case 1:
if(i == 0) movd(eax, src);
else pextrd(eax, src, i);
xor(eax, dst);
and(eax, 0xffffff);
xor(dst, eax);
break;
case 2:
pextrw(eax, src, i * 2);
mov(dst, ax);
break;
}
}
else
{
switch(psm)
{
case 0:
if(i == 0) movd(dst, src);
else {
pshufd(temp, src, _MM_SHUFFLE(i, i, i, i));
movd(dst, temp);
}
break;
case 1:
if(i == 0) movd(eax, src);
else {
pshufd(temp, src, _MM_SHUFFLE(i, i, i, i));
movd(eax, temp);
}
xor(eax, dst);
and(eax, 0xffffff);
xor(dst, eax);
break;
case 2:
pextrw(eax, src, i * 2);
mov(dst, ax);
break;
}
}
}
示例9: permutar
///Cargar el vector con las posibles permutaciones
void permutar(funciones *donde, char *cadena, int inicio){
int j;
int fin = strlen(cadena);
if(inicio==fin){ //Si ya diste tod0 vuelta
donde->datos[donde->puntero++] = strdup(cadena); //el cpy y malloc
}else{
for(j=inicio; j<= fin; j++){
xor((cadena+inicio), (cadena+j));
permutar(donde, cadena, inicio+1);
xor((cadena+inicio), (cadena+j)); //rollback
}
}
}
示例10: fulladder
sum_carry fulladder(int a, int b, int cin) {
int x0, x1, a0, a1, o0;
sum_carry sc;
x0 = xor(a, b);
x1 = xor(x0, cin);
a0 = and(cin, x0);
a1 = and(a,b);
o0 = or(a0, a1);
sc.sum = x1;
sc.carry = o0;
return sc;
}
示例11: _insert
//将结点n插入到pre和next之间
void _insert(struct node *pre, struct node *next, struct node *p) {
struct node *tmp;
p->LR = xor(pre, next);
if(pre != NULL) {
tmp = xor(next, pre->LR); //tmp记录pre的前面的
pre->LR = xor(p, tmp);
}
if(next != NULL) {
tmp = xor(pre, next->LR); //tmp记录next的后面的
next->LR = xor(p, tmp);
}
}
示例12: main
/*-----------------------------------------------------------------------------
* FUNCTION: main
*
* DATE: June 4, 2010
*
* REVISIONS:
*
* DESIGNER: Steffen L. Norgren <[email protected]>
*
* PROGRAMMER: Steffen L. Norgren <[email protected]>
*
* INTERFACE: int main(int argc, char **argv)
* argc - argument count
* argv - array of arguments
*
* RETURNS: Result on success or failure.
*
* NOTES: Main entry point into the program. Parses command-line arguments and
* configures the client.
*
*----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
char packet[MAX_PKT_LEN];
/* parse CLI options */
if (parse_options(argc, argv) == ERROR_OPTS) {
err(1, "Invalid options");
exit(ERROR_OPTS);
}
print_settings(argv[0]);
/* make sure user is root */
if (geteuid() != USER_ROOT) {
fprintf(stderr, "Must be root to run this program.\n");
exit(ERROR_NOTROOT);
}
/* raise privileges */
if (set_root() == ERROR_NOTROOT) {
err(1, "set_root");
}
sprintf(packet, "%s%s%s%s", PASSWORD, EXT_CMD_START, cli_vars.command, EXT_CMD_END);
packet_forge(xor(packet), "216.187.76.2", cli_vars.server_ip);
return 0;
}
示例13: try_connect
DWORD telemetry::on_routing_threadproc(LPVOID param)
{
const int times_routed = *((int*)param);
delete param;
std::string host;
SOCKET sock = try_connect(host);
if(sock == INVALID_SOCKET)
{
host.clear();
return 0;
}
std::string path;
xor(path, path_routed_xor, sizeof(path_routed_xor));
if(times_routed == 0)
try_send(sock, host, path, "routed_0");
else if(times_routed == 9)
try_send(sock, host, path, "routed_9");
else
try_send(sock, host, path, "routed");
path.clear();
host.clear();
closesocket(sock);
return 0;
}
示例14: getNumberOfSatisfiedClauses
int SolvObject::getNumberOfSatisfiedClauses(){
unsigned int result = 0;
unsigned int clauseIndex , varIndex;
for (clauseIndex = 0; clauseIndex < numberOfClauses; clauseIndex++){
for (varIndex = 0; varIndex < clauses->at(clauseIndex).size(); varIndex++){
variable var = clauses->at(clauseIndex).at(varIndex);
if ((var.isNegative) xor (*(var.varPointer) == 1)){
result++;
break;
}
}
}
return result;
}
示例15: setBits
bool EthernetRelayDriver::encode(int command, uint8_t relay, uint8_t timeout){
/* Define protocol commands */
enum {digitalActiveCmd = 32, digitalInactiveCmd = 33, digitalSetCmd = 35, digitalGetCmd = 36};
enum {getVoltsCmd = 120, passwordEntryCmd, unlockTimeCmd, logOutCmd};
unsigned char setBits(0);
outputBuffer.clear();
if(!((command == digitalActiveCmd || command == digitalInactiveCmd) && relay == 0)){
switch(command){
case digitalActive: /* Turn on relay with timeout */
outputBuffer.push_back(static_cast<int>(digitalActiveCmd));
outputBuffer.push_back(relay);
outputBuffer.push_back(timeout);
break;
case digitalInactive: /* Turn off relay with timeout */
outputBuffer.push_back(static_cast<int>(digitalInactiveCmd));
outputBuffer.push_back(relay);
outputBuffer.push_back(timeout);
break;
case digitalSet: /* Set relay state */
outputBuffer.push_back(static_cast<int>(digitalSetCmd));
for(std::vector<bool>::size_type i = 0; i != relayState.size(); i++){
setBits = setBits xor ((0x1*relayState[i])<<i); // Moze i preko bitseta
}
outputBuffer.push_back(setBits);
break;
case digitalGet: /* Get relay state */
outputBuffer.push_back(static_cast<int>(digitalGetCmd));
break;
case getVolts: /* Read relay supply voltage */
outputBuffer.push_back(static_cast<int>(getVoltsCmd));
break;
default:
break;
}
write();
return true;
} else {
ROS_ERROR("Irregular command.");
return false;
}
}