C++ :: Extracting Nibbles (Number Represented In Binary)

Nov 29, 2013

If I have a number 117, represented in binary as : 01110101 and I wanted to grab the top nibble. What would be the decimal value I would be extracting?

Would it be 0111 or 0101 decimal values 112 or 5 or is my understanding completely wrong?

View 11 Replies


ADVERTISEMENT

C++ :: Extracting From Loops - Run X Number Of Times And Produce A Prize Each Time

Sep 19, 2013

so i have a loop that will run x number of times and each time it will produce a prize which is a certain sum of money. I need to a way to sum all the money earned. I am thinking there should be a way to extract the prize one for each time the loop runs but i am not sure how to do that.

#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

int main() {
cout <<"Option A: Drop one chip into one slot" << endl;

[Code] .....

View 2 Replies View Related

C++ :: Adding Two Numbers Represented As Strings?

May 19, 2013

I need to make a small program with a function with this prototype: void f(char *a,char *b) that adds two numbers represented as strings without using conversion operators or other tricks.

View 8 Replies View Related

C++ :: 2 Dimensional Vector Represented As A Class

Nov 5, 2014

I have to create a class to represent a 2 dimensional vector. I need to include certain member functions such as a function to find magnitude of the vector, and one to find the dot product of that vector with another vector, and several others too. That's all fine. A stipulation of the problem is that I must include a constructor which can take cartesian form of the vector and a constructor which can take polar form of vector. Since this involves overloading the constructor the best solution I have come up with is to create the object with either doubles or floats so that the compiler can choose the correct constructor. This seems like a really bad idea. Is there a way I can get the compiler to choose the correct constructor without doing it using the precision? Here is a sample of my header file, there are many more member functions

class Vector{
public:
Vector(double x, double y, double v, double w){
myArray[0]=x;
myArray[1]=y;
additionalArray[0]=v;
additionalArray[1]=w;

[Code] .....

In my .cpp file the object is created with either four doubles or four floats depending on which constructor I want to implement. There must be a better way. Additional Array is created for use in member function which require calculations with a second 2d vector.

View 1 Replies View Related

C++ :: Find Normal To A Terrain Represented By A Texture

Mar 27, 2014

The following function finds the normal to a terrain represented by a texture. I found it somewhere online , it works but i couldn't understand the math behind it. So , How (or Why ?) does it works ?

//psuedo code
Vector2 normal(x,y) {
Vector2 avg;
for(int w = -3; w <= 3; w++) {
for(int h = -3; h <= 3; h++)

[Code] ....

View 6 Replies View Related

C++ :: Convert 8-digit Binary Number To Decimal Number?

Jul 6, 2013

Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.

Sample Output 1:

8-bit Binary Number => 11111111
Decimal Number = 255

Sample Output 2:

8-bit Binary Number => 10101010
Decimal Number = 170

Sample Output 3:

8-bit Binary Number => 101010102
Number entered is not a binary number

#include <iostream>
using namespace std;
int main()
{
int num;

[code]....

View 2 Replies View Related

C++ :: Convert Binary Number Into A Decimal Number

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "8-bit Binary Number=";
cin >> num;

[Code] .....

How can I get started with the body?

View 7 Replies View Related

C++ :: Convert Binary Number Into Decimal Number?

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

#include <iostream>
using namespace std;
int main()

[Code].....

May I know that how can I get started with the body?

View 5 Replies View Related

C++ :: Count Number Of 0 In Binary Number

Apr 11, 2013

i am writing a program that accepts a decimal number from the user and convert it to binary numbers. After the conversion, i should count the number of 1's and 0's in the said binary number. I got upto converting and counting 1's using Brian Kernighan’s Algorithm. But, i can't seem to get it to count the number of 0's.

#include <iostream>
#include<bitset>
using namespace std;
int main() {
int num,count=0,Zero,count1 =0;
cout<<"Enter the number:";
cin>>num;
string binary;

[code].....

View 7 Replies View Related

C :: Extracting Second Row From Array?

Mar 1, 2015

I'm having trouble trying to extra the second row from the array:

Code: double data[10][10] = {{0,5,10,15,20,25,30,35,40,45},{0,13,22,37,54,62,64,100,112,126}};

When I do this, it posts the entire array:

Code: int x,y;
for(x=0;x<2;x++)
{
for(y=0;y<10;y++)
{
printf("%.0lf ",data[1][y]);
}
}

View 5 Replies View Related

C :: Binary Number To Decimal

Mar 30, 2014

I am very new to programming and have been working on a program that can receive decimals or binary numbers and convert them. The decimal --> binary works fine. For some reason I cannot figure out I cannot get the "BinaryToDecimal" function to perform. By putting a "printf" into the for-loop.

Code:

#include <stdio.h>#include <string.h>
#include <math.h>
char* ReverseString (char _result[]) {
int start, end, length = strlen(_result);
char swap;
for (start = 0, end = length-1; start < end; start++, end--)

[code]....

View 2 Replies View Related

C++ :: How To Get Half Of The Last Binary Number

Nov 11, 2013

For example if we have 101010 First half is 101 which you get by multiplying 101010 * 10 ^-3

now how do you get the second half (010) ??

View 2 Replies View Related

C/C++ :: Binary Number Into Decimal?

Sep 10, 2014

I have a code and am asked to modify it so that it will take as input as unsigned binary number up to 16 digits in length and convert it into its equivalent decimal number and output that decimal number.

All I know is that I use library function strlen() in <cstring> to calculate the length of the input string.

I also know I have to use something called pow(2,4);

//pow (); is found in cmath

I was told to use sum = sum >>16-l; (l is the length of />/>

#include <iostream>
using namespace std;
int main() {

[Code]....

View 4 Replies View Related

C++ :: How To Take Binary Number As Input

May 31, 2013

how to take binary number as an input, generate partial products by bit-wise multiplication and in last step to add all the partial products to generate final products".

View 5 Replies View Related

C++ :: Extracting Numbers From A String

Dec 5, 2014

So, I have a string and I need to extract numbers from it. I've tried different things but they are not working. So, Here is what I have:

int main() {
string myString;
char *strPtr;

cout << "Enter a string to evaluate: " << endl;
getline(cin, myString);

[Code] ....

View 10 Replies View Related

C++ :: Extracting File Name From Path?

May 17, 2013

I have a string like this

const char *filename = "C:/Qt/progetti/worlds/fasr.world";

then I have a string like this

char *pathdir = "C:/Qt/progetti/worlds";

I would get this string: "worlds/fasr.world" how should I do ?

View 6 Replies View Related

C/C++ :: Extracting Strings From Files

Feb 15, 2013

We have an assignment to produce code to gather a string of input from the user in which they are entering a date. We then have to extract parts of that string to make substrings, and display different formats for the date(I will add my code in here so you can see what I have done). It took me a long while plucking away at this to understand this part. You will see that at the end of my code I have opened a file months.txt. We were provided with a file which states months corresponding to dates. I.e. 01January 02February 03March 04April, and so on until December. Exactly how I have typed it is how it is in the file.

I understand how to open and extract what is in the file as a string. I have extracted this as a string called myMonth (as you can see in the code as well) NOW,

I am supposed to have the program search for the month in the file, matching that to the month the user has input earlier, and then use the number infront of that month. I understand the basics of using find(), and making substrings. But how on earth do you get the computer to correlate what the user has input for a month, to finding that in the file, and then using the correct number.

Here is the code I have done so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string myDate; // Date input from user;
string myMonth; // Input from months.txt

[Code] ....

View 1 Replies View Related

C :: Convert Number To Binary From And Base Up To 10

Dec 7, 2014

I had an exercise that required me to convert a number to binary (base 2) which as simple enough.

Code:
#include <iostream>#include <iomanip>
#include <cmath>

using namespace std;
void Conversion (int n);
int main () {

[Code] .....

I now have a follow on exercise that requires me to convert to binary from ant base up to 10, i thought this would just be replacing the 2 with a variable obtained form the user, but i am having problems as within the function i am getting an error that i haven't passed enough arguments and i cant see why i get this. I did the following:

Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
float Conversion (int n, int b);

[Code] ....

View 2 Replies View Related

C++ :: Encoder And Decoder For Binary Number

Jun 8, 2013

I have to do a code for a encoder, decoder and converter for binary number and hexadecimal...

View 1 Replies View Related

C++ :: Padding Zeroes Onto A Binary Number

Feb 24, 2014

The following piece of code is supposed to output the binary representation of a given integer and it does exactly that. However, if the given integer is 2, then output is 01. Is there a way to make the program output 0001. I am working on a C program that outputs 4-bit gray code.

#include <stdio.h>
#include <math.h>
int main(void) {
long int n=2;
while (n) {
if (n & 1)
printf("1");

[Code] ......

View 2 Replies View Related

C/C++ :: Number To Binary Converter Program?

Sep 21, 2014

I recently wrote a program to convert numbers to binary in c++, Well here it is:

#include <iostream>
void recur(int convert) {
if(convert == 0) //if input is 0 , return nothing. {
return;
}
recur(convert/2); // divide convert by 2, get only a 1 or 0

[Code] ....

View 13 Replies View Related

C/C++ :: Program To Print Out Binary Value Of 16 Bit Number

Sep 22, 2013

Write a program to print out the binary value of a 16 bit number.

Create integers i, count, and mask.

Set 'i' to a hex value of 0x1b53.

Set mask to a value of 0x8000. Why?

print a line to show the hex value of i and then the leader for the binary value like this: Hex value = 1b53 Binary=

Use a for loop to loop 16 times and print 16 digits, using count as the loop counter

To test for each digit value, bitwise and 'i' with 'mask'

when the result for the bitwise and is true, print the number '1'

when the result for the bitwise and is false, print the number '0'

then shift mask one place to the right

print a new line and then quit

Use prtscrn and make a hard copy of the code with the console output.

Extra: use the modulus of count and print a space after every 4th digit to make the binary easier to read

The output should look like this: Hex value = 1b53, Binary= 0001 1011 0101 0011

so far this is what i have

#include <stdio.h>
#include <stdlib.h>  
int main() {
    int i, count, mask;
    //   1B53  0001 1011 0101 0011
    //   8000  1000 0000 0000 0000
    i = 0x1b53;

[Code] ....

it is telling me that there is an "else" without previous "if", also is the program that I wrote correct?

View 3 Replies View Related

C++ :: Extracting Decimal Numbers From A String?

May 16, 2014

Extracting integers from a string is trivial, but I am unable to find a function or code that will extract decimal numbers from a string.

I have a string that looks something like this:
" Asdf 1 1.3825 4.0000 12.0000 1.9133 0.1853 0.9000 1.1359 4.0000 "

Any tips on extracting the numbers (in decimal form) and storing them in a vector?

View 5 Replies View Related

C++ :: Extracting Polynomial Coefficient From String

Nov 30, 2013

I want to extract polynomial coefficient out of a string recieved by input, for example if i enter 4x^3+2x^4+3 , the resulting out put be : 2 , 4 , 0 , 0 , 3

View 10 Replies View Related

C++ :: Extracting String From Text File

Jun 5, 2014

I have a program here that writes employee information into a text file called employee.txt. I don't have a problem writing into the text file.

I'm supposed to enter the employees ID and search for it. Then pull up all they're info.

This is what I have.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
ifstream inFile;
ofstream outFile;

[Code] ....

This is the text file
Viktor,Luc,552,123 Home,5000
Joe,Luc,553,123 House,7000

View 7 Replies View Related

C/C++ :: Extracting Information From Data File?

Apr 20, 2015

Create a simple data file like the example shown below containing the 4 dates below plus 10 or more additional dates. The file should include 1 date per line and each date should have the form MonthNumber-DayOfTheMonth-Last2DigitsOfTheYear with no extra spaces. All dates should be in this century. No error checking for invalid dates is necessary.

My Output displays like

February -19,1991

How do I get my program to ignore the dash between the dates?

#include <fstream>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
const int M = 13;

[code]....

View 1 Replies View Related







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