C++ :: Getting Bits In RDX After Multiply (x64)

Aug 13, 2013

Using the old fashioned (unsigned) multiplication instruction in x64 assembly multiplies RAX (64 bit register) by a 64 bit register. The answer is stored in RDX:RAX (i.e. the answer is 128 bits). Is there any way, using native c++ to get the value in RDX (higher 64 bits)? One I can think of is: right/(limit/left) e.g. if we are limited to a byte then 97*123 would overflow:

97/(255/123) = 46 times, which is RDX's (if it was one byte) value. But this is too inefficient. Is there a fast way?

View 4 Replies


ADVERTISEMENT

C++ :: Retrieve Double Number - Store 8 Bits Of Number In One Field And 16 Bits In Another

May 14, 2013

I am working on a project where I need to retrive a double number and store 8 bits of the number in one field and the other 16 bits in another field. the code below gives me an error.

lata= lat>>8;
latb = (lat & 0xff);

The error states that & and >> are illegal for double. With this in mind, can I use these on a double. If not what can I do to achieve what I am trying to do?

View 1 Replies View Related

C :: Multiply One Array By Another

Dec 1, 2014

I am trying to multiply one array by another, for example:

enter 5 letters
enter 5 numbers,2 3 4 2
output= qq, www, tttt, ee

but im stuck with the last calculation.

Code:

#include <stdio.h>
#include <stdlib.h>
int main() {
char array1 [5];
int i, j;
int array2[5];

[code]....

View 1 Replies View Related

C/C++ :: How To Multiply Two Matrices Together

Mar 7, 2014

I haven't found anything that small for Matrix multiplication i was just going to ask about how i would multiply to matrices together in c++ as easy as possible, so for example say a i have the following

[2 0 1 0 * [3 0
6 -1 0 2] 0 3
1 2
3 1]

How would i multiply these together. Here is the example

Attached image(s)

View 11 Replies View Related

C :: How To Divide / Multiply Two Variables

Feb 26, 2013

I am new to C programming and I am just wondering how to multiply / divide two different variables which the user type in as the promt is asking like this:

Code:
void inmatning3 (double *a, double *b) {
printf("Mata in tv217 stycken flyttal: "); /* asks you to type in 2 numbers */
scanf("%lf %lf", a, b);
}

When you've enterd the two numbers I need to eather multiply or divide the two variables "a" & "b" .....

View 5 Replies View Related

C++ :: Multiply Values In Array

Jan 27, 2015

If we have array like

int numbers [] = {3,4,8,9,6,3,2,58,6,3,2,5};

how can we fast do smth like 3*4*8*9*6*3*2*58*6*3*2*5

also numbers[0]*numbers[1]*numbers[2] etc

all must be in one loop....

View 3 Replies View Related

C++ :: Multiply Two Dynamic Arrays

Mar 28, 2014

By using operator overloads i need to be able to * two dynamic arrays;

this is what i have so far

MyInt operator* (const MyInt& x, const MyInt& y) {
MyInt Temp;
int carry = 0;
if(x.currentSize > y.currentSize){
for( int i =0; i < y.currentSize; i++)
for(int j = 0; j < x.currentSize; j++)

[Code] ....

View 7 Replies View Related

C :: How To Correctly Multiply With Negative Numbers

Jul 24, 2013

I've been working on this program to create a simple desk calculator for a school assignment, and I managed to finish. All we had to do was add, subtract, multiply, and divide positive integers - and I was able to do that just fine. This program got me thinking though, because I do not know how to write commands to multiply/divide negative numbers.

In fact, when I divide a number like 21 by 4, it comes out to 5 because I don't know how to allow it to compute remainders (which wasn't a requirement for my program). This intrigued me so I've been trying to figure it out for the last few days but to no avail. Here's my code:

Code: void flush_buffer(){
int ch;
while ((ch = getchar()) != '
' && ch != EOF);

[Code]....

And just know that my code works perfectly fine, I'm not here for troubleshooting it. I just want to know what I can change to allow negative values to be correctly computed.

View 12 Replies View Related

C/C++ :: Multiply 2 Variables That Go From 0 To 7 - Logical Operators?

Apr 9, 2015

#include <iostream>
using namespace std;
int main(){
int polje[8][8];{
for(int i=0;i<8;i++)
for(int j=0;j<8;j++) {

[Code] .....

I don't get any errors,the program works. The problem is that it doesnt work how it should. This is a simple program that multiplies 2 variables(i and j)that go from 0 to 7. The problem I have is with the logical operators,i want the program to skip multiplication with 0 and when the 2 variables are the same value. When i try using only 1 logical operator it work.

View 2 Replies View Related

C/C++ :: How To Multiply And Divide 2 Numeric String

Mar 28, 2014

I want to multiply and divide 2 string that contains number. For example

s1=4 and s2=8 s1*s2=32 ,s2/s1=2

I don't want convert string to integer and do it.because i deal with big numbers.and these should be in string form.

View 1 Replies View Related

C++ :: Multiply String To Int - Could Not Find Match Operator

Jan 5, 2015

Whats wrong with my program ? It always says that coundn't find match operator ? What can i do ? I want to multiply string pay to int HOURS.

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main () {
system("color 8e");
string ID,name, address,No, pos ,pay, hanap;
string hours;

[Code] .....

View 3 Replies View Related

C++ :: Two Dimensional Array - Multiply Mxn Matrix Of Integers By Nxr

Jan 8, 2015

Using two-dimensional arrays, write a program which multiplies an mxn matrix of integers by an nxr

matrix of integers.

INPUT FIRST (2x2) MATRIX:

Type in 2 values for row 1 separated by spaces: 3 4

Type in 2 values for row 2 separated by spaces: 5 7

INPUT SECOND (2x2) MATRIX:

Type in 2 values for row 1 separated by spaces: 1 1

Type in 2 values for row 2 separated by spaces: 2 2

3 4

5 7

TIMES

1 1

2 2

EQUALS

11 11

19 19

View 1 Replies View Related

Visual C++ :: Multiply Defined Symbols When Linking To DLL

Oct 24, 2013

I'm building two DLLs - let's call them DLL_A and DLL_B. DLL_A builds as a standalone entity but DLL_B needs to link to the lib file for DLL_A (i.e. it imports some functionality from DLL_A). While linking DLL_B I see lots of errors taking the following form (bear in mind that port.cpp and port.h are source files in DLL_B:-

DLL_A.lib(DLL_A.dll) : error LNK2005: "public: bool __this call
std::vector<class std::basic_string<char,struct std::char_traits<char>,
class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,
class std::allocator<char> > > >::empty(void)const " (?empty@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V
?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QBE_NXZ)

already defined in port.obj

I'm not sure if I'm reading that correctly but to me, it seems to be saying that some STL components are somehow getting exported from DLL_A (std::vector maybe?? Or std::string??) and that they conflict with similar objects already in port.obj. Sure enough, when I used dumpbin /EXPORTS on DLL_A there did seem to be some evidence that that was true. So my next step was to examine the source code for port.obj. Of course, strictly speaking I should be examining some code from DLL_A but it has hundreds of source modules so I figured that I should start by identifying whatever it is in DLL_B that's throwing up the conflict (since I at least know which module the conflict is in!).

When I examined the source files for port.obj, std::string seems to get used quite often - but fortunately I could only find one occurrence of std::vector.

In port.h it occurs here:-

Code:
class DLL_B_API Port : public boost::noncopyable {
public:
// c'tors + d'tors
int get_connections (std::vector<std::string> &) const;
// rest of class

In port.cpp it occurs here:-

Code:
int Port::get_connections (std::vector<std::string> & c) const {
if (!port_engine.available()) {
c.insert (c.end(), _connections.begin(), _connections.end());
return c.size();
}
return port_engine.get_connections (_port_handle, c);
}

Is there anything in there that would be causing the above linker error? It's entirely possible that I'm looking in the wrong place but I suppose I've got to start somewhere....

I just found a possible clue in one of the header files for DLL_A, where I found this class declaration:-

Code:
namespace PBD {
class DLL_A_API Searchpath : public std::vector<std::string> {
// Whatever...
};
}

Might that be causing std::vector<std::string> to get exported?

View 5 Replies View Related

C :: Entering Two Positive Integers To Multiply Together - Program Won't Compile

Aug 24, 2013

I'm trying to get my C program to compile but it's not working at all. I've programmed a little in C++ before but I'm not used to C. Here's my program so far:

Code:
int main(void){
// Establishes variables
int num1, num2, product;
float quotient;

[Code] .....

It keeps giving me an error message as follows:

"/usr/bin/ldrelabwk2: file format not recognized; treating as linker script
/usr/bin/ldrelabwk2:1: syntax error
collect2: ld returned 1 exit status"

View 11 Replies View Related

C :: Program That Multiply Very Large Numbers (out Of Range Of Long Int)

Jan 10, 2014

I have to write a program, that multplicates very large numbers (out of range of long int). It's said that i need to use arrays and read the numbers as strings. My problem is to end function called "mnoz:, because i don't know how to sum the multiplicated values of arrays a and b.

Code:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include "winbgi2.h"
#include<string.h>
#define roz 10000
char lan(char a[])

[Code] ......

View 1 Replies View Related

C++ :: Fatal Error - One Or More Multiply Defined Symbols Found

Nov 13, 2014

Im getting this error:

"fatal error LNK1169: one or more multiply defined symbols found"

Here's my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
int main () {
cout << "Avoiding Technology" << endl;
bool status = true;
int location;
int a,b;

[Code] ....

View 3 Replies View Related

C++ :: Multiply Number Of Seat And Ticket - Return Value Not Working

Dec 20, 2013

I have a code in here that u will multiply the number of seat and the number of ticket. I think I got the correct return value but it's still not working when i times it it always = 0 ...

#include<iostream>
#include<iomanip>
#include<string>
#include<stdio.h>
#include<fstream>
int getBill(int seat);
int getPos(char seat);

[Code] ....

View 14 Replies View Related

C++ :: Program That Add / Subtract / Multiply Or Divide Two Integers - Incorrect Answers

Oct 7, 2012

Create a program that adds, subtracts, multiplies, or divides two integers. The program will need to get a letter (A for addition, S for subtractions, M for multiplication, or D for division) and two integers from the user. If the user enters an invalid letter, the program should display an appropriate error message before the program ends. If the letter is A (or a), the program should calculate and display the sum of both integers. If the letter is S (or s), the program should display the difference between both integers. When calculating the difference, always subtract the smaller number from the larger one. If the letter is M (or m), the program should display the product of both integers. If the letter is D (or d), the program should divide both integers, always dividing the larger number by the smaller one."

And here is the test data. I am posting the results from my desk-check table.

operation first integer second integer answer
A 10 20 30
a 45 15 60
S 65 50 15
s 7 13 6
G -1
M 10 20 200
d 45 15 3
d 50 100 2

Then, I transferred my program into a source file. Here it is:

//Exercise16.cpp - display answer of two integers

#include <iostream>
using namespace std;
int main() {
//declare variables
int firstInteger = 0;

[Code] ....

After putting in the data, everything worked fine, except the last two operations, which are M (multiplication) and D (division). All the answers for the last two operations essentially give me a 0.

View 4 Replies View Related

C++ :: Assigning Bits A Value Of 0

Feb 12, 2014

I am having a problem assigning bits a value of 0. The data is a 16 bit integer the bits greater than the 12th bit have garbage either a 0 or a 1. I would like to assign all bits greater than 12th bit the value 0 no matter what their values are. Whats the best approach.

View 5 Replies View Related

C++ :: Shifting Bits Away And Back

Mar 25, 2014

Value x is a 32-bit unsigned integer 3:

00000000000000000000000000000011

If we use bitwise-shift to shift all bits to the right by 2, x is 0:

00000000000000000000000000000000

If we then do a bitwise leftshift on x by 30, do we end up with:

11000000000000000000000000000000
or
00000000000000000000000000000000

In other words, when we perform right shift which clips away the least most significant bits, and then do a left shift, is it possible for those bits to reappear?

View 2 Replies View Related

C++ :: Retrieving First Three Bits Of A Number

Apr 25, 2013

I am trying to retrieve the first three bits of a number. The code that I am using should work but it isn't giving me the correct result when trying certain numbers. Below is the code I am using:

unsigned short num1, num2 = 0;
unsigned short num = 65535// binary 111111111111111
num1 = num && 0x07;// gives me 1 but should give 7(111)
num2 = num >>3;//gives me 8191, which is correct

Why I am not getting the first three correct bits(111)?

View 2 Replies View Related

C++ :: How To Reverse Bits For A Number

Sep 3, 2013

I am working on a project where I need to reverse bits for a number.

For example, if I have 110111100000000 I need to reverse it to 0000000001111011.

View 19 Replies View Related

C++ :: How To Set Certain Bits Of Unsigned Short

Aug 8, 2013

I have a double variable and depending on certain conditions I need to set certain bits of an unsigned short Variable. For example, if double var is odd I need to set the 15th bit of the unsigned short variable.

View 4 Replies View Related

C++ :: How To Write Bits To A Disk

Mar 30, 2014

I'm trying to write a program that writes data to a disk in C++ without caring about it's file system. Here is what I can do so far:

#include <iostream>
#include <unistd.h>
#include <fcntl.h>
using namespace std;
char buffer[] = "Wow! I'm writing this data to a disk without puttting it into a file!";
int main(){
int Disk=open("/dev/sdb",O_RDWR);
write(Disk,buffer,sizeof(buffer));
close(Disk);
return 0;}

But this program can only write ASCII characters to the disk. But what if I want to mainipulate bits on the disk, how would I do that?

View 3 Replies View Related

C/C++ :: How To Locate The Lowest 8 Bits In A 64 Bit Key

Jul 15, 2014

I am trying to encrypt a plaintext using DES in C. I read about the algorithm and how it works, but when i came to write the code i struggled. :

How to locate the lowest 8-bits in a 64-bit key ?

How to shuffle the plaintext according to the algorithm description ? (I read about bitwise operations, but i still cannot understand how i can use them to transfer for example the 5th bit to the location of the 30th bit)

Left shifting the key would not wrap the bits, so i just bitwise or with a mask that will add the bits that did not wrap around?

View 1 Replies View Related

C/C++ :: Add 8 Bits - Return The Character

Oct 10, 2014

I'm working on an assignment where I have to read an image in the PPM format. This format consists of a header that contains the parameters and the rest is raw bits.

I have to work with a modified PPM image that contains a secret message. This message is stored in the first X number of bytes. To decode a single character I would have to look at the lowest level bit of 8 bytes and return that as a character, then repeat this for the length of the message.

The code below is what I have so far, but I do not get the expected output but instead I get smiley-faces.... or other ASCII characters depending on the shift.

char buffer = 0;
int MsgSize =(size*8);
int nRead = 0;
printf("The secret message is displayed below: ");
for(i; i<MsgSize; i++) {

[Code] ....

View 5 Replies View Related







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