C++ :: Difference Between Int And Short Int
Aug 19, 2014size of int is 2 bytes and of short int is also 2 bytes.The range of values for int and short int are the same.
Then why int and short int are used? only int or short int is enough ....
size of int is 2 bytes and of short int is also 2 bytes.The range of values for int and short int are the same.
Then why int and short int are used? only int or short int is enough ....
i am using the below logic. but it gives me error when i am setting the bit_position 15 or 16. i suspect, the problem with the integer range.
short bit_map, bit_position
bit_map = bit_map | ( 1 << bit_position )
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 RelatedI'm trying to return a short int in a function..This is my function signature :
short int* StartRecord(int seconds)
this is my array :
short int waveIn[NUMPTS];
I'm trying to get the data into an array :
short int arr [] = StartRecord(3);
getting this error: Error2error C2440: 'initializing' : cannot convert from 'short *' to 'short []'
I've stored a binary pattern in what is interpreted as an unsigned short.
unsigned short byte_one = 128;
I've done some bitwise manipulation and want to store it back into an array, however, it needs to be null-terminated.
buf[1] = byte_one;
How do I null-terminate this?
I am using print/sprintf with a "%i" format string. Works fine if the input is indeed a 32bit integer. But how can i put in 8/16 bit (ie short & byte) 'integers'? If i just throw them in, they are always taken as unsigned, as the topmost bit/s is/are casted to zero... [URL] ....
View 3 Replies View RelatedI'm having trouble reading a block of bytes into a vector of short ints. My code is as follows:
Code:
FileStream.seekg(2821);
vector<short> g_Data;
int iter = 0;
g_Data.reserve(maxNumOfInts);
[Code] ....
The relevant block of data starts at offset 2821 in the file. Every two bytes are a signed short integer. What's odd is that it's giving me the correct results only part of the time. At offset 1052421 and 1052422 there are two bytes 40 and 1F that are correctly read in as 8000, but at offset 1052415 and 1052416 bytes 88 and 13 are read in as -120 instead of 5000.
I don't see anything wrong with my code, though, unless I'm misunderstanding completely how to convert an array of two bytes into a single float. Is my method correct? Better still, is there some way to just convert en mass an array of bytes into a vector of signed short ints?
Any function of simply converting character array to a short int?For example. char array[4]={'0','2','f','f'}; to short int 767?
View 3 Replies View RelatedI've been working on this project which inserts data for different types of books lately, and I'm trying to utilize inheritance and polymorphism. The issue I've been having is after I create an object with my MediaFactory, I go to insert data into that type of object, but it won't reach the correct child class. The parent class in this case is MediaData. The class I'm trying to reach is Childrens, and the class that falls in between is called Book. The function I'm calling to insert the information is setData(ifstream&). This function simply places the information from a txt file into an object with the insertion operator.
Right now the program runs into the setData function of Book instead of Childrens. I need Childrens so I can enter all the required attributes (title,author,year). The call to this function is in MediaManager through the function called buildMedia, and my test is running into the case if (type == 'Y'). From there a pointer of type MediaData is created and pointed to a new object returned of type Childrens. I'm using my debugger in Xcode which does show that the correct object type (Childrens) was created.
I've tried a couple things so far. First I created another function called getData. From there I passed in *media and infile (txt input file) into that function, which then passed it right into setData with a pointer to the object and infile in the parameter. That didn't work, so I also tried going back into Childrens and removing MediaData from all my virtual functions and replacing it with Book. I got the same result when that happened; It morphed into Book class instead.
I have a portion of my UML as a reference. Childrens is a Book; Book is a MediaData. I also included all code for MediaManager, MediaHash, MediaFactory, MediaData, Book, and Childrens.
I did not include the operator overloads in the .cpp files to eliminate some redundancy.
//-----------------------------------------------------------------------------
// MediaManager.h
// Manager class for MediaData type objects
//-----------------------------------------------------------------------------
#ifndef MediaManager_H
#define MediaManager_H
#include "MediaHash.h"
#include "MediaFactory.h"
#include "MediaData.h"
using namespace std;
class MediaManager {
[Code] ....
How can i write a function that will read an "unsigned integer" into a variable of type "unsigned short int"? i can not use cin >> inside the function.. so i am looking for atleast a hint!
View 16 Replies View RelatedI have done some experimentation on rvalue references with the TDM-GCC 4.6.1 compiler and made some interesting observations that I cannot explain away with theories. I have a very simple program that does not deal with objects but int primitives and that has defined 2 functions:
foo1 (returning a local variable by rvalue reference) and
foo2 (returning a local variable by value)
#include <iostream>
using namespace std;
int &&foo1();
int foo2();
int main() {
int&& variable1 = foo1();
[Code] .....
It seems the value returned by foo1 and received by variable1 dies out after some time - perhaps, a brief period of some milliseconds. Notice that I have prevented cout from printing "My name is softwarelover" by commenting it out. If I allow that statement to run, the result is different. Instead of printing 5, 0 it prints 0, 0. Seems like it is because of the time-delay introduced by "cout << "My name is softwarelover." that 5 turns into 0.
Is the above how an rvalue reference is supposed to behave when referring to a primitive integer which a function returned by reference as opposed to return-by-value? By the way, why is it 0, why not garbage?
Notice also that variable2 never seems to die out, no matter how many times I print it with cout! variable2 refers to a primitive integer which a function returned by value, not return-by-reference.
#include <functional>
using namespace std;
template<typename...Args>
void on(function<void(Args...)> f) {
function<void(Args...)> fn; // this line causes error C2059: syntax error : '<fake-expression>'
}
int main() {
function<void()> f;
on(f);
}
What's the difference between 'f' and 'fn'?
Code: enun{go, stop, ready, halt}
vs
enum status{go, stop, ready, halt}; and where is enumeration with name is benefficial.
Creating a C# program to prompt the user to choose the correct answer from a list of answer choices of a question and if the answer is wrong then try to prompt the same question again with do while loop but it is not working as it suppose to be.
class Program
{
static void Main(string[] args {
char UserChoice = ' ';
do {
Console.WriteLine("What is the command keyword to exit a loop in C#?");
Console.WriteLine("a.quit");
Console.WriteLine("b.continue");
[Code] ....
But if i use int instead of char in this program and replace a, b, c and d with 1, 2, 3 and 4 then this program work fine. What is wrong in this code when using char
How i can easly calculate the difference between two dates ?
Example :
Date 1 = 12 March(3)
Date 2 = 24 November(11)
Result = 258 days
how to do this in C++ ?Btw i don't want to use date functions or something like that.I want to do it with simple math formula.
#include<iostream>
using namespace std;
int main() {
double x,i;
cout<<"Enter the value of the number
[Code] ....
why I am not getting exact square root if I take x as double,but if I am taking it as int I got the correct result.
What is the difference between HAS-A and IS-A relationship?
View 7 Replies View RelatedI just wanted to know what's the difference between these two types of main functions:
Code: int main (int argc, char** argv){ ... }
Code: int main (int argc, char* argv[]){ ... }
I am new to programming.. What is the difference between structures and unions in C
View 2 Replies View RelatedOther than the theoretical difference between cout and cerr where the former puts values to the monitor and the latter puts values related to errors to the monitor, is there any real difference here? Why not use cout when you want to send anything to monitor? Why use cerr at all?
View 7 Replies View RelatedI just figured out that some std functions (for example: copy) need the resource and target objects have iterators to work. Otherwise, the compiler rejects. In case of two arrays, declared as:
double myA[100] = {};
array<double, 100> myB = {};
myA[0] is like a pointer, myB.begin() an iterator, if I do not make any mistake. So, what is exactly the difference between the pointer and the iterator here? They all give the access to elements.
If I need the target of copy to be an array like myA which cannot give an iterator, is there a way to make the command "copy" work for it?
What is the diff between strings and arrays? Here is sample:
By String:
#include <iostream>
#include <string>
using namespace std;
int main () {
string mystr;
[Code] .....
By arrays:
#include <iostream>
using namespace std;
int main () {
char name[256], title[256];
[Code] ....
which is preferable and can i pick characters one by one in string?
Similar to Pascal’s triangle, the difference triangle has some interesting properties that find applications in various fields of the natural and applied sciences. In simple terms, a difference triangle is a set of integers arranged in an inverted triangle where each inverted triangle triad has its lower element equal to the difference (absolute value) of the two elements in the upper row. A difference triangle can be created from a sequence of integers forming the uppermost row by iteratively taking differences between consecutive terms to form the next row until a single-element row is created.
Example Consider the sequence 5, 8, 13, 21, 34, 55 from the Fibonacci series as the uppermost row of the difference triangle. The difference between successive elements form a new set: 3 (= 8 – 5), 5 (= 13 – 8), 8 (= 21 – 13), 13 (= 34 – 21), and 21 (= 55 – 34). The process can then be repeated until there is only one element left giving the following difference triangle:
5 8 13 21 34 55
3 5 8 13 21
2 3 5 8
1 2 3
1 1
0
Problem Write a program that forms a difference triangle using a given series of numbers as topmost row.
vector<int> *vec; allocate memory and
suppose vec conatins 10 values then
erase(vec->begin(),vec->end());
vec.clear();
both should be used or any one one is fine to erase all ??
I know this isnt the correct forum to put this in but i dont know where else to post this and get a quick answer...
Im looking up logic gates and theres a option between bipolar and CMOS and i was wondering whats the differnce
For example
NAND Gate 4 Element 2 Input CMOS 14-Pin Plastic Dip Tube
NAND Gate 4 Element 2 Input Bipolar 14-Pin Plastic Dip Tube
#include <stdio.h>
#include <stdlib.h>
int b_diff (int, int);
[Code].....
I am trying to take two arrays H[], and V[] and call each element to compute the bit difference(Hamming distance) and return that back to the main function to be used in calculating pixel_phase and pixel_smoothing. I'm getting an error that bit_diff cannot be used as a function and I've tried renaming it but nothing seems to work.
[ int b_diff (int a, int ] is how it should actually look.int b_diff (int a, int is how it should actually look).