C++ :: Variable Length Integer Operations?
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
ADVERTISEMENT
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
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
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
Jun 15, 2014
changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).
View 4 Replies
View Related
Nov 27, 2012
Why this class doesn't work for Subtraction, Division and Square Root. When I try to get results for Subtraction, it output right answer, but with any trash. And When I try to get answer for Division and Square Root, it just brakes and don't output anything. For Addition and Multiplication class work correctly.
Its the link to this class [URL]
View 2 Replies
View Related
Oct 30, 2014
I'm doing a bitwise operations on 2 bytes in a buffer, then storing the result in a variable. However, I sometimes get a non-zero value for the variable even though I'm expecting a zero value. The relevant portion of the code is as follows.
Code:
unsigned int result = 0;
long j = 0, length;
unsigned char *data;
data = (unsigned char *)malloc(sizeof(unsigned char)*800000);
[Code] ....
I'm expecting result to be zero when my data[j] and data[j+1] are 0xb6 and 0xab respectively, which is the case for most of the time. However, for certain values of j, my result is strangely not zero.
Code:
j = 62910, result = 64
j = 78670, result = 64
j = 100594, result = 64
j = 165658, result = 512
j = 247990, result = 128
j = 268330, result = 512
j = 326754, result = 1
j = 415874, result = 256
j = 456654, result = 1024
j = 477366, result = 512
It appears that these strange result values are all powers of 2, with a 1 bit appearing somewhere in the unsigned int.
I'm not changing the value of result anywhere else in the code, and when I print out
Code: (unsigned int)(((data[j]^0xb6)<<8)|(data[j+1]^0xab))
I get 0, but somehow when it gets stored in result, it's no longer zero. I really don't understand what could be wrong.
View 1 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