C++ :: Advanced Data Namespace - Exchanging Byte Sizes
Jul 27, 2013
I have an advanced data namespace in which I hope to be able to read a data variable of any type and transfer it's bytes into another type of a multiple size.
i.e.
char[4] -> int;
int -> short[2];
short -> char[2];
char[2] -> short;
but I'm having some trouble, I get the following errors (because as a template it must compile from start)
template<typename T1, typename T2> void stepBytes(UCHAR size1, UCHAR size2, T1 in, T2& out){
if(size1 == 0 || size2 == 0)
return;
if(size1 % size2 != 0 &&
size2 % size1 != 0)
[Code] ....
So, why's this error appearing?
View 2 Replies
ADVERTISEMENT
Dec 26, 2013
I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...
i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....
------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";
[Code] ....
When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.
The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.
I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.
When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..
input = input / BASE; I get C9 where I expected to get 48.
My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?
View 6 Replies
View Related
Apr 23, 2012
I'm trying to parse some binary data in the form of an array of bytes and I've come across something that is confusing me related to the representation of data as chars versus ints. It's a bit of a long story, but the byte array contains a mixture of character data and integer data which I' having trouble unravelling. The problem seems to arise from the issue below:
Code:
const char * ch_arr = "abcd";
const unsigned int * ui_arr = (const unsigned int*)ch_arr;
cout << ui_arr[0] << endl;
unsigned int ui = 'a';
ui = ui << 8;
ui |= 'b';
ui = ui << 8;
ui |= 'c';
ui = ui << 8;
ui |= 'd';
cout << ui << endl;
I expected both the output lines to be the same, since they contain the same bytes (I believe), but I get:
Code:
1684234849
1633837924
View 4 Replies
View Related
Apr 18, 2012
let's say I have an IntPtr that points to the raw data of System.Drawing.Bitmap. is there any way to create a byte array from that IntPtr without copying the data? I'm a pretty experienced C++ programmer, so I can call ToPointer() on it and convert to a byte* to work with it as a pointer, which is no big deal for me, but using a pointer and doing pointer arithmetic increases the risk of bugs, so I'd prefer not to do it that way if there's another way.
View 4 Replies
View Related
Jul 7, 2014
I'm asking how to create a function with default parameters with the possibility to init the parameters that you need.
Code Example :
#include <iostream>
int func(int a = 1, int b = 2, int c = 3, int d = 4) {
return a + b * c / d;
[Code] .....
View 3 Replies
View Related
Oct 9, 2013
Last night I was trying to see if is possible to multiply one number to another without using any given function(like pow) or the multiply sign or whatever. Just using addition and subtract signs (+and -) with a for loop. It worked.
Now I am trying to understand if is possible to elevate one given number (inserted by the user) to another number without using again any function or the multiply / divide/ etc functions. Just add and subtract functions.
View 3 Replies
View Related
Sep 6, 2013
#include <iostream>
#include <array>
#include <sstream>
[Code].....
I need to add thevArr[I] and vArr1[I] and store in vArr2[I] but I cant figure out how to drop the value or replace with a 0 if vArr is bigger than vArr1. IE: 1st number: 123 2nd number: 4567
Ill get something like this:
1 2 3
4 5 6 7
5 7 9 -827349
View 2 Replies
View Related
Aug 3, 2014
I create new dialog window. I add container Fixes and change Fixed properties : - AutoSize, +Expand, +Fill to enable other widgets. I add Text View, Textview is inside GtkScrolledWindow which has property X and Y but not Height and Width. If GtkScrolledWindow has scrollbars, its size is fixed, if not - size depends on the content Textview and grows when I type text. I want not to grow control if I type Text but want my own size. It is possible?
View 7 Replies
View Related
Oct 15, 2013
I'm building a box to take in several arrays of different lengths. one group happens every 10 seconds. one of them happens every 5 seconds. this is from a weather station.
10 sec
subgroupA[14]
subgroupB[24]
subgroupC[17]
subgroupD[12]
subgroupE[34]
5 sec
subgroupC[17]
I plan to retransmit them, substantially unchanged at a lesser rate to save radio power over a serial data link. buried in groupD, I want to change a few chars before retransmit.
I don't want to go to the trouble of doing a structure for each of them since most will be resent unchanged. some entries are chars, some are decimal, some are a mix. I guess it might be convenient to further define groupD, maybe not.
what is the best way to declare the group? I want them to be contiguous since that's how they will end up in the tx buffer. Each subgroup has its own checksum, so I planned it this way to make checksum more convenient.
View 6 Replies
View Related
Feb 7, 2013
I'm trying to find the MAX and MIN integer sizes that are entered in by the users. I know that we need to sort [i] and [j] in my function to figure out which is the highest and lowest score correct?
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
[Code].....
View 4 Replies
View Related
Feb 15, 2013
I have a paradigm where a integer before gets enqueued to a queue in a vector, the loop of queues is searched and integer is enqueued to a queue which has minimum size among the queues. the following code shows the operation
#include <vector>
#include <queue>
std::vector<std::queue<int> > q
[Code].....
next i am trying to extend my paradigm with the condition, that the integers should be enqueued to the shortest queue until the count of the shortest queue is less than or equal to count of any another queues in the loop of queues.
i want to do something like the code shown below
#include <vector>
#include <queue>
std::vector<std::queue<int> > q
[Code].....
View 4 Replies
View Related
Apr 9, 2013
The size of fundamental types is not guaranteed. Apparently, all the standard guarantees is a hierarchy of sizes, and some minimum representable value range.
Specifically, a char is not guaranteed to be one byte. Also, the sizeof operator always returns 1 for the size of a char, even if the actual size is not eight bits.
Isn't this a huge problem for portability? It seems like 2+ byte characters would break all kinds of things. For example, fstream::write() takes a char * and a byte-length argument. If you ported from a 1-byte-char platform to a 2-byte platform, wouldn't that screw up all your write()s? Worse, you couldn't even detect the problem without trial and error, since sizeof would just lie to you.
I've never actually seen a platform where char wasn't 1 byte, but it sounds like a disaster waiting to happen.
View 6 Replies
View Related
Mar 24, 2012
I am using 2 ARRAYS OF DIFFERENT SIZES in One 2-Dimensional Vector, and my output is not correct. The arrays are size 4 and size 13.
I want COLUMN 0 to have: 55, 66, 77, 88.
I want COLUMNs 1-12 to have 1,2,3,4,5,6,7,8,9,10,10,10,11 in EACH ROW. It would seem that the 2nd loop for the size 13 array would need to loop 4 times in order to fill 4 rows, however, I'm not sure how to do that. Here is what I have so far in code and output:
#include <iostream>
#include <vector>
using namespace std;
int main() {
int typeArray[4] = {55,66,77,88};
int valArray[13] = {1,2,3,4,5,6,7,8,9,10,10,10,11};
[Code] ....
OUTPUT:
55 0 0 0 0 0 0 0 0 0 0 0 0
1 2 3 4 5 6 7 8 9 10 10 10 11
77 0 0 0 0 0 0 0 0 0 0 0 0
88 0 0 0 0 0 0 0 0 0 0 0 0
How to populate rows correctly?
View 2 Replies
View Related
Feb 15, 2014
I'm writing a program where I need to generate a conversion table for wrench sizes with the following columns: Size (Inches) [Fraction], Size (Inches) [Decimal rounded to 3], Next Bigger Metric (mm), Difference (Inches) [Next Bigger Metric-Inches], Closest Metric (mm) [to original size], and Difference (Inches) [Closest Metric-Inches]. I've created the column for the Size in fraction form relatively quickly but I cant seem to produce the decimal version. Instead, I get 0.000.
Code:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
[Code] ....
View 4 Replies
View Related
Feb 28, 2014
I'm working on a homework assignment that asks me to roll two die a user given number of times, find the roll sums, and a few other things. I'm working on it one module at a time and I'm running into two big problems so far.
The first problem is that my int variable rolls changes to a number within the random number generator range of numbers after I run rolldie. I got around this by making a const equal to the user entered value of rolls just so that I could continue developing the program.
My second problem is that the values of the arrays resultsOne[] and resultsTwo[] are changed after running findsum(). Why this is happening and I even tried passing them as const, but that changed nothing. We just started learning about passing arrays to functions, so there might be something big that I'm missing.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void rolldie(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo);
void findsum(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo, int tossSums[], int sizeOftossSums);
[Code] ....
View 8 Replies
View Related
Jun 10, 2014
i know using namespace std; is important to wite as it contain cout,cin,etc........but is that namespace std is contained inside iostream header file OR iostream header file is contained inside namespace std ......
View 1 Replies
View Related
May 4, 2013
It seems as though more experienced programmers tend to write code with std::cout, std::string, etc., whereas less experienced programmers always write using namespace std;. They also tend to assume that, in code snips, it is already included.
Why is this? If it's a dislike, what's the problem with it? As stated in the namespaces tutorial on this site, a namespace can be overridden if need be. Is it the case that you have written your own namespaces? Or that you so seldom use things like the STL and stdin/out that it just isn't necessary?
View 5 Replies
View Related
Mar 18, 2015
#include<iostream>
#include<conio>
nmaespace num {
void disp(int x) {
[Code] ....
View 1 Replies
View Related
May 19, 2013
Can we put using namespace std; in a header file? Someone told me not to do it, but I don't know why...
View 2 Replies
View Related
May 2, 2013
I have two header files, A, B.
A.h
namespace test {
struct info
{
int a;
}
}
B.h
#include "A.h"
int main {
test::info.a = 10;
}
However, it has an error. I don't quite understand how to use namespace.
View 2 Replies
View Related
Nov 29, 2013
exportmain.cpp
Code:
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
// Create an empty property tree object
using boost::property_tree::ptree;
#include "kwxport.h"
#include "resource.h"
[Code] ....
How can I make boost:roperty_tree:tree get recognized by the compiler?
View 2 Replies
View Related
Jun 3, 2012
What is difference between an class and an namespace? You can put functions in both class and namespace?
View 1 Replies
View Related
Mar 11, 2013
I've verified this on ubuntu 12.10 and on windows/mingw, and found that g++ version 4.7.2 seems to have broken thread/mutex support.
View 11 Replies
View Related
Jan 8, 2015
Why is using namespace needed in linux but not in turbo c++?
View 1 Replies
View Related
Jan 11, 2013
I want to create a namespace named MyNS.
Can I define it in multiple files?
I mean:
file1.h
namespace MyNS {
const int File1 = 0;
} file2.h
namespace MyNS {
const int File2 = 1;
[Code] .....
View 6 Replies
View Related
Aug 23, 2014
I have two files that I want to compile:
main.cpp
Code:
#include <iostream>
using namespace std;
int ReadNumber();
void WriteAnswer();
[Code] .....
The compiler complains:
io.cpp||In function 'int ReadNumber()':|
io.cpp|3|error: 'cin' was not declared in this scope|
io.cpp||In function 'void WriteAnswer()':|
io.cpp|7|error: 'cout' was not declared in this scope|
io.cpp|7|error: 'endl' was not declared in this scope|
In io.cpp file, should I put the two statements ("include <iostream>" and "using namespace std") at the top, outside of the functions?
Or should I put the two statements inside each of the functions?
View 4 Replies
View Related