C :: Modulus Operator In While Loop

Oct 23, 2013

Code:
while ((y % 12) != 0) {
y++;
}

I liked that the above code does not put the result into a variable and then test the variable which would use more memory, and more lines of code. Is this thinking bad?

View 10 Replies


ADVERTISEMENT

C++ :: Operator Definitions - Modulus Remainder Calculation

Oct 18, 2014

where are operators defined in C/C++? in headers or compiled code?

looking for the definition of how % modulus is calulated

View 19 Replies View Related

C/C++ :: Use Modulus Operator With Double Type Variables?

Mar 13, 2013

how can we use modulus operator with double type variables

View 2 Replies View Related

C++ :: Overloading Modulus Operator To Return Remainder Of Division Between Two Floating Point Numbers

May 27, 2013

Say I wanted to overload the modulus operator to return the remainder of a division between two floating point numbers. Why isn't a custom double operator%(double, double) allowed even though that function isn't available in the standard anyway?

View 5 Replies View Related

C++ :: How To Use Modulus

Mar 16, 2013

if i have 4 intergers for example :

1378 2496 3587 5389

how can i use the modulus operator to disect them so i can get the first number of each integer .what i mean is how can i take 1 form 1378 and 2 from 2496 etc...

View 16 Replies View Related

C :: RSA Implementation And N Modulus

Aug 18, 2013

I have to develop minimalistic implementation of RSA algorithm in C for an embedded device.

I'm doing that for two days but I have run into a problem. The N modulus is the limitation for the maximum message value to be encrypted with RSA.

For example theoretically RSA-1024 can encrypt/decrypt messages 1024 bits long but I still cannot understand how to choose p and q values to produce N == pow(2, 1024).

Is it possible to encrypt/decrypt 1024 bits long messages in practice if the N < pow(2, 1024)?

So far I'm getting the following results

Code:
Encrypting with RSA
d=15689981, e=21, n=16484947
In=16484942, Encrypted= 6074492, Out=16484942 (OK)
In=16484943, Encrypted= 5468920, Out=16484943 (OK)

[Code] ....

View 10 Replies View Related

C# :: RSA Decryption With Only Modulus And Exponent

Nov 26, 2014

How to perform RSA decryption with just the modulus and public exponent. I know that in RSA the private key does the decrypt, but thats not what I need to do. It is actually more of a verify used to recover information for the purposes of integrity (stupid I know) but its the problem I have to solve. Basically I need to do an RSA operation with the modulus and public key. When I try it I receive the error:

System.Security.Cryptography.CryptographicException: Key does not exist.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.RSACryptoServiceProvider.DecryptKey(SafeKeyHandle pKeyContext, Byte[] pbEncryptedKey, Int32 cbEncryptedKey, Boolean fOAEP, ObjectHandleOnStack ohRetDecryptedKey)
at System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[] rgb, Boolean fOAEP)
at IssuerPublicKeyRecoveryApp.Form1.PerformVerification() in C:devMarvinDevIssuerPublicKeyRecoveryAppIssuerPublicKeyRecoveryAppForm1.cs:line 543.

My Code is as follows:
try{
//Create a new instance of RSACryptoServiceProvider.
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) {
//Build the RSA key parameters to perform decrypt
RSAParameters RSAKeyInfo = new RSAParameters();

[Code] ....

I have verified that my values are good on : [URL] ....

This example is strait off the MSDN website, and I realize it says that you need the private key information on the RSA import. For what I am doing, I do not have that, since I am doing a decrypt(not really). Since I know that the Math of an RSA operation is actually identical weather you are doing encrypt or decrypt, and it is just a convention of length for the exponent, I tried to do an Encrypt operation to decrypt the data, and the error checking caught that it was the wrong length in stead of performing the operation.

View 1 Replies View Related

C++ :: Modulus And Random Number Generation?

Apr 13, 2014

I am making a random number generator. I have fixed all issues except for one. I am supposed to ask the user for how many digits the user wants the numbers to have. How many numbers does the user want. Then randomly generate numbers according to what the user entered. So if the user said 2 digits and wanted 4 numbers then it would output 4 random numbers in the range of 10 to 99.

My notes from class show this working correctly. And it does work correctly. But I don't understand the math here or how the modulus effects it. I was able to get 1 and 2 digits to work but once I get to 5 it doesn't generate numbers correctly. it will only generate number s

Code: int min =1;
int max = 9;int number1 = rand();
cout << number1 % max + min << " "; h

Here is the 3 digit code I have. I also need to figure out how to make it unique so no number generates more then once. I think the issue may be that the numbers are not unique and it is generating the same number and that is somehow effecting the numbers it is outputting. It is either that or my math is wrong.

Code:
if (intLength == 5) {
for (int i = 0; i<intQuantity; i++) {

[Code]....

View 6 Replies View Related

C/C++ :: Getting Divide By 0 Error When Using Modulus With Number Below 1

Jan 31, 2013

I am trying to get a remainder of a number with a = 0.9144, rm = ry % a; however, I keep getting a divide by zero error (I believe due to the program rounding 0.9144 down to the integer 0).

View 2 Replies View Related

C :: How To Determine If Modulus 16 Of A Pointer Address Equals 0

Mar 21, 2013

For part of my program in class I have to take a pointer address and determine if it is equal to 0 modulus 16. But I can't figure it out.

View 1 Replies View Related

C++ :: Namespaces / Classes - Perform Operator Overload With Insertion Operator

Mar 22, 2013

I'm doing a refresher for C++ and have gotten to operator overloading. I'm trying to perform an operator overload with the insertion (<<) operator, but I have encountered a problem.

Here's my class [In a header file "Shinigami.h"]

#include<string>
namespace K{
class Quincy;
class Shinigami{
friend std::ostream& operator<<(std::ostream&, const Shinigami&);

[Code] .....

If the operator function is a friend of the 'Shinigami' class, why doesn't it recognize any of it's private members? I need it to be in this file because I'm doing a bit of association with the 'Quincy' class.

I thought it was the namespace, but I included that.

View 9 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C :: How To Use Conditional Operator

Jan 25, 2013

i know

Code: (condition) ? true-clause : false-clause

but how do you use an array as the condition, how will the code look?For example i want to write

Code:

string numbers[5] = {"one","two","three","four","five"};
numbers == "one" ? thumb : again; thumb and again will replace something else. Don't worry about them.

how do i say that if the numbers array is representing "one" then it replaces as "thumb", otherwise "again".

View 5 Replies View Related

C++ :: Class Using New Operator

Jan 5, 2015

Is it usual to rely completly on the new operator in constructors/copy constructors. What if new trows an exception? The application ends and that's it? The new operator can be placed where it can't be catch like in constructor initialization list. What kind of practice I should adopt when using "new" in those cases?

The sample code below is taken from here... [URL] ....

class MemoryBlock {
public:

// Simple constructor that initializes the resource.
explicit MemoryBlock(size_t length)
: _length(length)
, _data(new int[length])

[Code] .....

View 9 Replies View Related

C++ :: Overloading I/O Operator

Oct 26, 2013

In this below example:

class Point {
private:
double m_dX, m_dY, m_dZ;

[code].....

In that situation, << does not call the overloaded function, but rather calls the << method defined in the i/o library, which prints a message to the controlling terminal. So once it prints the message to the terminal, it then returns the out instance. Why return the out instance rather than a boolean like true? As you can see from the example, once the message is printed to terminal, out is not used anymore.

View 2 Replies View Related

C++ :: How To Overload Operator Twice

Jul 10, 2014

Here's my question. I'm coding a basic Linked List class (for the purpose of understanding and having fun, I know about STL), LList.

I have overloaded the [] operator so it returns the data of the index-th node in the list, for example, if I code

LList x;
....
cout<<x[5];

it prints the data of the 5th node in the list (for fun I decided to index from 1 to infinity).

My question: Now I want to be able to assign the value to the index-th node data, using [] and =, for example, I want to be able to write:

LList x;
.....
x[5] = 121;

How can I do that?

View 3 Replies View Related

C++ :: WAP Using Ternary Operator

Aug 13, 2014

1.WAP in C++ to enter marks in 3 subject and calculate percentage and grade.cond given below (Using Ternary operator)

Per Grade
90-100 A
80-90 B
70-80 C
0-70 D

2. WAP to enter 3 no.s in and print them in ascending and descending order .(Using Ternary operator)

View 8 Replies View Related

C++ :: STL Map Compare Operator

Jun 13, 2012

In stl map, if I insert two keys, say a and b. It looks like compare operator is called twice. First time a<b is called and second time b<a is called. Why are both a<b and b<a called?

View 6 Replies View Related

C++ :: Operator New Without Implementation?

Aug 5, 2013

Here is the code,

Code:
class A {
private:
void* operator new(size_t size);
};
int main() {
return 0;
}

The code above compiles fine without errors. But operator new might not have implementation body?

View 3 Replies View Related

C++ :: Operator Overloading IStream

Jan 26, 2015

I am working on this assignment...

Code:
#include <iostream>#include <iomanip>
using namespace std;
class Score
{
private:
// Value at which we'll shift digits from million_counter to billion_counter
static const int THRESHOLD = 1000000000;

[Code] ....

It gives the errors:
line 105 error: million_counter was not declared in this scope
line 106 error: normalizeScore was not declared in this scope
line 110 error: million_counter was not declared in this scope
and more of that until
line 170 error: no match for 'operator<<' in 'std:perator<< <std::char_traits<char> >((* & std::cout), ((const char*)"a+b is ")) <<operator+((*c(const Score*) (& a)), (*(const Score*)(& b)))'

I thought that because i declared friend functions, they would be able to access the private variables of the class.

View 2 Replies View Related

C++ :: Dot Operator Versus Arrow

Jun 26, 2014

I understand that the dot operator is:

Code: a.b "a"

is the actual object (not a memory location) and "b" is the member. I also understand the arrow to mean:

Code: a->b "a"

is a pointer to a struct and "b" is it's member so "a" is dereferenced then "b" is given.

Here is where I get a little confused. I have a class:

exampleclass.h
Code:
#ifndef EXAMPLECLASS_H_INCLUDED
#define EXAMPLECLASS_H_INCLUDED
class exampleclass{

[Code].....

Also if ec1 had a public variable and I wanted to access it would it be referenced the same way as the method I call in ec1?

View 4 Replies View Related

C++ :: Scope Resolution Operator?

Feb 21, 2013

I have done alot of googling for the scope resolution operator and Ive gained a bit of an understanding as to what it does i know it can distinguish between global and local variables, but I see it used to access methods/members of classes such as this example, why not just use a dot instead to access it?:

sql:: Driver *driver;

Why is the scope resolution operator being used here?

View 11 Replies View Related

C++ :: Operator Overloading In A Correct Way?

Apr 1, 2013

Well... I observed, as a non-professional programmer that "overloading operators" has some strict rules and some conventions... so any operator can differ from another. In order to have a clearest idea, I'd like to ask you to specify, for every operator, the correct (or best) way to overload it.

There are cases where you define &operator and cases where you define operator (without "&"). There are cases where operator are defined as "friend" inside class, and other cases where operator is declared externally.

example: ostream &operator<<
(why it uses & ??)

So can we have a summary for all kind of operators?

View 19 Replies View Related

C++ :: How To Able To Overload A Multiplication Operator

Apr 24, 2014

How would i be able to overload a multiplication operator that if, in the main example(0, 5, 0) * example (0, 5, 0) is given, it gives me 25?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved