C++ :: Variable Length Integer Subtraction
Aug 24, 2013
On a controlled buffer of unsigned char it is possible to do subtraction faster than if you followed standard mathematical rules, here is an example:
typedef unsigned char uchr;
uchr num1 = 5; //00000101
uchr num2 = 3; //00000011
num2 = ~num2; // 11111100
++num2; // 11111101
uchr num3 = num1 + num2; // 00000010(2) - computer truncates result to fit char
Since you will be working with a buffer you don't even need to worry about truncating the final bit because the add function will not be able to reach it - unless it is given the ability to grow the buffer in which case you just set the bit to 0 yourself
View 8 Replies
ADVERTISEMENT
Aug 25, 2013
I intend to reference this thread from another thread so I do not clutter that thread with code
/* This code is relied on by some of the functions I will post */
typedef unsigned long long zxumax;
typedef signed long long zxsmax;
[Code]....
View 13 Replies
View Related
Aug 25, 2013
I already have the standard one that mimics the one taught in schools written but I've found that there is a faster formula that can be used however I not sure how to implement this. The formula is called the "Fast Fourier Transform", any simplistic example using this function base:
typedef unsigned int uint;
typedef unsigned char uchr;
uint umul( uint* src, uint val ) {
uint des = *src;
[Code] ....
If you're doing the buffer based functions then I have some pre-made functions you may need. [URL]
View 6 Replies
View Related
Dec 25, 2014
What I'm trying to do is to assign the length of a string to an integer variable. This is what i tried, it did not work.
Code:
printf("Enter a string
");
fgets(test_pass, 30, stdin);
strcpy(x,(strlen(test_pass)));
printf("%d", x);
This was just a test, and it did not compile. How to do this?
View 4 Replies
View Related
Oct 3, 2013
The programming problem is supposed to take a decimal number from a user and turn it into a binary number. Here is my code:
for (int i=0; i< count; i++) {
binary[i] = decimal % 2;
decimal = decimal/2;
} cout << binary[2] << endl;
decimal is the number entered by the user.
binary [] is the char array and count is... you know how many times the for loop will turn. So my question is, how do i know the length of the number ? Any function that shows the integer length ? because its impossible to know what count is equal to. like 100 is 3.
View 3 Replies
View Related
Nov 23, 2013
Any good function that get the length of an integer in C++
I do know of str.length(), however i want something similar for integers
View 1 Replies
View Related
Apr 2, 2014
How to write a function that receives an integer array along with its length. the function calculates and returns the sum of the squares of all the odd numbers in the array?
View 2 Replies
View Related
Oct 24, 2014
How do you prompt the user to enter the number of elements for the array and use that information to creatr a variable length array? And then how do you prompt the user to enter in a number for each element of the array and scan in the appropriate numbers? the numbers are double precision floating point.
for example,
Enter the numbe of elements in the array: 3
Enter element 0: 3
Enter element 1: -1
Enter element 2: 4
I know it starts with
int main() {
double N;
int a[size];
printf("Enter the number of elements in the array:" );
scanf("%f", &size);
//I'm pretty sure this is wrong
View 8 Replies
View Related
Nov 13, 2013
This code snippet compiles and runs fine
Code:
#include <stdio.h>
int main(void) {
int i, a[i];
i=2;
for(int n=0; n<=i; n++)
a[n]=0;
[Code] .....
It prints out 3 "0", but when slightly changed
Code:
#include <stdio.h>
int main(void) {
int i, a[i];
i=200;
for(int n=0; n<=i; n++)
[Code] ....
It compiles fine but core dumps when run, how come? i'm using gcc version 4.4.7, and compiling like this
gcc -std=c99 test.c -o test
View 14 Replies
View Related
Mar 6, 2015
The WinAPI has a struct like this for raw input:
Code:
typedef struct tagRAWINPUT { RAWINPUTHEADER header;
union {
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
} data;
[code]...
The definition of the struct doesn't show it but the documentation says that bRawData is variable length. sizeof(RAWINPUT) will not be the correct size when the data field is of RAWHID type so how do you allocate a variable with automatic storage type that has the right size for the entire struct? You can get a header that has the size for the entire struct but how do you actually allocate storage space for the data without using malloc? I've seen some example code that used a char array but that violates aliasing rules and there are also alignment issues with that approach.
View 5 Replies
View Related
Oct 10, 2013
I believe that everything is fine except that I can think of the condition can be inserted inside the parentheses ..
#include <iostream>
using namespace std;
int main() {
int i=0, k=0;
char *string_n, **matrix, temp;
[code].....
View 2 Replies
View Related
Nov 28, 2013
I want to ask for a number as an input during runtime and then create an 2-dimensional array of size as specified by user. i.e. if the user inputs 3, the array should be of size 3X3, and likewise...
View 9 Replies
View Related
Feb 25, 2015
I want define Variable that has all amount of between two integer example: 2-4
View 1 Replies
View Related
Oct 10, 2014
In my program I'm trying to add 200 to the variable named "gold". I thought this would work, but I guess it's not:
int gold2=gold+200;
int gold=gold2;
View 7 Replies
View Related
Nov 25, 2014
Consider the below initialization of x.
int x = 0x01234567;
If x is stored in RAM as given below, what would be the address x in both case?
(if image is invisible please follow this link)
Assume that size of integer is 4 byte.
View 4 Replies
View Related
Oct 16, 2014
this program is not giving to chance to enter the ooplevel value.
Code:
#include <iostream>
using namespace std;
const int SLEN = 30;
struct student {
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
// getinfo() has two arguments: a pointer to the first element of
// an array of student structures and an int representing the
[Code]...
View 3 Replies
View Related
Dec 6, 2014
I need to create a stack with the container being an unsigned int. I tried to put in numbers up to four bits each and have the program read the numbers individually. This is the code I am using:
void push(int n)//item n is pushed onto the stack, throw exception on full stack {
string str="Error";
if (isFull())
throw str;
[Code] ....
When I have tested it, the program is reading the numbers as one whole number. For example, I put in the number 2, and it displays the number 2. Then I put in 2 again, but this time it displays the number 10, instead of 2 2.
View 2 Replies
View Related
Jan 24, 2014
How can I use an integer variable in a http command example:
int num, canal;
for (num =0, num < 10, num++){
canal = num;
system( "wget http:'/'/192.168.3.4/channel.cgi?channel= canal");
}
View 3 Replies
View Related
Mar 29, 2012
In the code below:
void test(int * i) {
i = new int;
*i = 10;
cout << "i: " << *i << endl;
[Code] ....
The outuput is:
i: 10
t: (some memory position).
If I really want to allocate an integer variable to t, i need to modify the void test(int * i) procedure to void test(int *& i).
View 2 Replies
View Related
Jun 2, 2013
what I need is to get the first integer from a file and assign it to a variable and the others integers to an array. Example: Thats my file content 5 4 6 7 8 0 and that would be the code:
Code:
struct Array{
int n;
int *v;
}
[code]....
View 8 Replies
View Related
Mar 27, 2014
I am trying to make sure no floating point numbers can be input at any time in my roulette program. My code is too long to put in one post so I shall piece it out
#include <iostream>
#include <iomanip>
#include <random>
#include <cstdlib>
#include <ctime>
using namespace std;
// structure of arrays to pass to functions
[Code] .....
View 12 Replies
View Related
Feb 8, 2015
I need to average integer measuring samples and store this variable, so that it can`t be changed.
I need to get the initial pressure reading from my bmp085 pressure sensor, an integer value between 0 and 10000 and store the initial value after program start, so I can compare the later readings to determine whether pressure went down or up. The value to store should also be integer, rounding errors don`t matter.
View 1 Replies
View Related
Nov 8, 2013
I need to have a program display an error message if the variable entered isn't an integer but then I want it to cin again. I have this but it doesn't work:
cout << "Enter an Integer: " ;
for (;;) {
cin >> var;
if (!cin) {
[Code] ....
I am not sure how to do what I want and this doesn't work, it just repeats That wasn't an int.. over and over again.
View 8 Replies
View Related
May 12, 2014
My intent was to convert the string variable for the year to an integer data type. The code compiles but now cannot run on my system. I'm not sure what's going as to what the program is displaying.
Objective: Prompt the user for two years. Print all Comedy movies that were released between those two years.
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <cctype>
using namespace std;
struct Movie {
string name;
[Code] .....
View 2 Replies
View Related
Apr 18, 2014
I am working on an assignment where I have to subtract two very large integers. How can I write it's code provided that I have both numbers in a character array with each index holding a fraction of the original number. Like if I have a number 123456789 in an array then
arr[0]='1';
arr[1]='2';
arr[2]='3';
arr[3]='4';
and so on. n
nNw if i have to subtract this number from an other number, how can I do that?
View 4 Replies
View Related
Mar 12, 2014
I am looking for simple code that subtract two time interval. I have time t1=5hour 30 minute and other time in 24 hour format. This code i written but it not working as expected
main() {
intTime1;
intTime2;
int hour=10;
int minute=5;
int second=13;
int h;int m;
[Code] ....
Is there any easy way of doing above code. Above two code section not working....
View 8 Replies
View Related