C++ :: Generate A Binary String Based On Hex Data

Apr 23, 2013

Generate a binary ascii characters(weird character ) based on Hex:54313032202020303030 data in C++

View 3 Replies


ADVERTISEMENT

C++ :: Create A Binary File Based On HEX Data

Apr 24, 2013

I want to create a binary file based on some hex data :

Ex Input Hex :54313032202020303030

Out put like :6      

View 2 Replies View Related

C++ :: Sorting Some Data Based On Values Of A String Of Bits

Apr 1, 2014

I have a problem I am working on where I need to sort some data based on the values of a string of bits. The strings look like this,

010000001110000000

there are 18 bits, 1 means a feature is present, 0 means the feature is absent.

Each of these string has 4 on bits. I need to sort them such that I have the longest possible runs with 3 of the same on bits. It doesn't matter which 3 bits are on, I am just looking to order them in blocks with the longest possible runs. As a second step, the ordered blocks will be sorted by size large>small.

The following data is ordered like I need it to be.

Code:
// block 1, run of 12, keys 1,2,11 are identical (key 12 is also identical)
011000000001100000
011000000001100000
011000000001100000
011000000001100000

[Code] .....

This is the sort order that I am looking for. I need to be able to take a list of the bit strings in any particular order and sort them into the order above. The algorithm would need to recognize that there are 4 on keys and then look for groupings of three common on keys.

This is more of an algorithm question than one about specific implementation in code. I generally assume that most programming problems have been solved one way or another, so I don't know much about analyzing and manipulating strings of bits.

Is there a standard method for this kind of pattern recognition?

View 14 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

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

C++ :: Generate A Report Based On Input Received From A Text File

Nov 5, 2014

Here is the assignment... Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy. And the second namespace globalType fys should derive the class level based on a four year school policy.

Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits

Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits

and this is the code I have so far...

#include <cstdlib>
#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;
enum class_level {FRESHMAN, SOPHOMORE,JUNIOR,SENIOR};
class_level classLevel;

[Code] .....

My main question is did I use the namespaces and enum correctly? And my second question is whats the best way to input the data from the text file? This is really where I get stuck.

View 3 Replies View Related

C++ :: Generate A Report Based On Input Received From Text File

Nov 7, 2014

Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy.
The second namespace globalType fys should derive the class level based on a four year school policy.

So I basically did it in parts and got everything working and then had to make the namespace so I had this:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };

[Code] ......

I know I have to clean it up and change it but it ran like it was suppose to. Then I tried adding the global namespaces and I this:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
class_level classLevel;

[Code] ....

with this i keep getting an error saying tys::deriveClassLevel: must return a value and tys::fys::deriveClassLevel: must return a value. I have been messing around with this part and struggling I thought I used the namespace to run the if statements with the criteria for the years of school. Basically I have been stuck for awhile and trying to change things around but I cant seem to get it to work.

View 2 Replies View Related

C++ :: Combine Multiple Vector Containing Binary Data To String?

Mar 16, 2012

Two questions:

1. I have some vector<unsigned char> containing binary data. I would like to combine them into one std::string. How is the correct way to accomplish this?

This is my best guess for sample code:

Code:
vector<unsigned char> data; //conatins some data
vector<unsigned char> data2; //contains more data
string temp(data.begin(), data.end());
temp.append(data2.begin(), data2.end());

Will this code work with binary data, or will it null terminate?

2. A similar problem.. I have some unsigned char* variables, and I want to combine them into one std::string. How can I accomplish this? will the member append() work here? or will it null terminate? Something like:

Code:
unsigned char* data; //conatins some data
unsigned char* data2; //contains more data
string temp(reinterpret_cast<const char*>(data));
temp.append(string(reinterpret_cast<const char*>(data2)));

Will the above sample code work without null termination?

View 4 Replies View Related

C++ :: Generate Report Based On Input Received From Text File - User Defined Namespace

Nov 11, 2014

Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy.
and the second namespace globalType fys should derive the class level based on a four year school policy.

Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits

Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits

NOTE : use ignore() function with ifstream objects whenever you want to ignore the newline character.

For example :
ifstream transferSchoolFile ;
transferSchoolFile.open("student_status.txt", ios::in);

while( !transferSchoolFile.eof()) {
getline(transferSchoolFile,name) ;
transferSchoolFile >> id >> credits;
transferSchoolFile.ignore(); //Used here to ignore the newline character.
….
}

I did this in parts so I got it working with a four year criteria without the user defined name spaces.

include <iostream>
#include <fstream>
#include <string>

using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };

[Code] ....

So that worked fine then I tried with name spaces -

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
class_level classLevel;

[Code] ....

I know I have some stuff to mess around with but I am currently stuck with two errors, first -

Error1error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartupC:UsersstephenDocumentsVisual Studio 2013ProjectsinputConsoleApplication1MSVCRTD.lib(crtexe.obj)ConsoleApplication1

then -

Error2error LNK1120: 1 unresolved externalsC:UsersstephenDocumentsVisual Studio 2013ProjectsinputDebugConsoleApplication1.exeConsoleApplication1

View 1 Replies View Related

C/C++ :: Generate Report Based On Input Received From Text File - User Defined Namespace

Nov 11, 2014

Program Description: Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student's name (lastName, firstName middleName), id, number of credits earned as follows :

Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110

Generate the output in the following format :

John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior

The program must be written to use the enum class_level :

enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;

and define two namespace globalTypes (tys and fys) for the function :

class_level deriveClassLevel(int num_of_credits) ;

The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.

The first namespace globalType tys should derive the class level based on a two year school policy.
and the second namespace globalType fys should derive the class level based on a four year school policy.

Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits

Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits

NOTE : use ignore() function with ifstream objects whenever you want to ignore the newline character. For example :

ifstream transferSchoolFile ;
transferSchoolFile.open("student_status.txt", ios::in);
while( !transferSchoolFile.eof()) {
getline(transferSchoolFile,name) ;
transferSchoolFile >> id >> credits;

[Code] ....

I know I have some stuff to mess around with but I am currently stuck with two errors, first -

Error1error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartupC:UsersstephenDocumentsVisual Studio 2013ProjectsinputConsoleApplication1MSVCRTD.lib(crtexe.obj)ConsoleApplication1

then -

Error2error LNK1120: 1 unresolved externalsC:UsersstephenDocumentsVisual Studio 2013ProjectsinputDebugConsoleApplication1.exeConsoleApplication1

View 2 Replies View Related

C++ :: Basic Array Based Binary Tree

Oct 20, 2013

I've been working on this assignment and but I know that I'm not handling my array properly.

#include<conio.h>
#include<iostream>
#include<stdio.h>
using namespace std;
class binaryTree {

[Code] .....

View 1 Replies View Related

C++ :: How To Generate Two Files And Write Data Into

Apr 5, 2013

I try to write my data into two different files and i just use something like this

ofstream myfile;
myfile.open("phase 1.txt");
if (myfile.is_open()) {
for(i=0;i<M; i++) {

[Code] .....

But it only generate the first file. How should i modify this?

View 2 Replies View Related

C++ :: Generate Random Data (fast)

Feb 20, 2013

I just want to know how fast can C++ generate data? For example, I have a downstream device that is connected to my pc via a Gigabit Ethernet, and I have to generate some pattern and send it over the Gigabit interface.

I was curious if there is a way that I can see how fast I can generate data? I was curious if I can exercise a good portion of the bandwidth ! for example, sending about 600 Mbits/sec.

How do I find out, first, whether I can do this with C/C++, and, second, how do I know how fast I am sending data?

View 4 Replies View Related

C++ :: Generate Data Set Of Angles Automatically And Provide Three Columns (Sin / Cos / Tan)

May 8, 2014

Given an array of angles A = [0 30 60 90 120 150 180 210 240 270 300 330 360]

Write a program that will generate the data set of angles automatically and provide three columns; sin(angle), cos(angle), tan(angle). Make this program as compact and readable as possible.

View 2 Replies View Related

C++ :: Generate Array Of Data Using Templates Into Programme Memory?

Apr 24, 2013

When you have constant arrays, they are stored in the programme memory space. Upon execution, they are copied into the data space for easy access. To save space in the data space, it is possible to stop it from being copied. Some compilers will deal with this by just specifying the array as const, g++ has a type modifier called PROGMEM.

In any case, the problem is that I'd like to generate some data, preferably without using an external programme to do it. Hence, my question using the template system. Now I could possibly use macro metaprogramming via boost instead of template metaprogramming, and I may have to go that route. However there are limitations, especially since its numbering system is only equivalent to an unsigned byte, which I possibly could use, but could become more messy than if I use the template system that has long long types as well as a whole slue of type safety mechanisms.

View 14 Replies View Related

C++ :: Generate A Sha256 Hash With Std String?

May 22, 2013

I am trying to generate a sha256 hash with std string, but i can't get this incomplete code puzzle to work [URL] .....

void main() {
string pbData1 = "HELLO";
BYTE* pbOutputBuffer;
CryptoPP::SHA256().CalculateDigest(pbOutputBuffer, (byte*)pbData1.c_str(), pbData1.size());
cout << pbOutputBuffer;
}

my problem is converting 'const char *' to 'const byte *' ..etc

View 1 Replies View Related

C :: Store Data In Binary File Then Use It To Find Inverse Of Matrix Form Of Data

Dec 6, 2013

I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.

Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();

[Code] ....

View 4 Replies View Related

C# :: Display Data In Text Box Based On ID

Dec 23, 2014

I have a area in my Project where i need to display a title and content in two text boxes. The Data base tables are:

ID | Title | Content

This is what I have so far, I know I am on the right track, I just cant figure out how to get each box to display based on the ID.

private void frmMain_Load(object sender, EventArgs e){
try {
string connStr = ConfigurationManager.ConnectionStrings["sdcAssistDB"].ConnectionString;
OleDbConnection dbConn = new OleDbConnection(connStr);
dbConn.Open();

[Code] ....

View 3 Replies View Related

C/C++ :: Change Data Based On Users Input?

Feb 7, 2014

Player is given choice of x number of Races This choice changes the player's base stats. Then player is given a choice of x number of Classes (archer, warrior, etc.) This choice determines how the player's stats will change upon leveling up.

#include <cmath>
#include <iostream>
#include <ctime>

[Code]....

View 7 Replies View Related

C :: Generate A Program That Will Allow User To Enter Data For A Stock And Calculate Amount Of Stocks

Oct 5, 2013

Okay, so my assignment for my C class is to generate a program that will allow the user to enter data for a stock and calculate the amount of stocks that ended up being positive, negative, and neutral.I tried to do this using one stock, here is my code;

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

Code:

void main()
{
float Neg;
float incst;
float shrs;
float bpps;
float crnt;
float crntcst;
float yrfes;
float pft;
float tpft;
}

[code]....

View 6 Replies View Related

C++ :: How To Stop Outputting Data Based On A User Input

Sep 27, 2013

how to stop outputting data based on a user input. The text file is as follows:

1. a
2. b
3. c

and the code I'm using is as follows:

int main (){
string line;
int search;
cout << "Enter a number from 1-3" << endl;
cin >> search;
search++;
ifstream myfile ("example.txt");

[Code]...

What I want to do is to just output number 1 (the whole line) if the user enters number 1. However, I get an error on the second condition w/c is the "&& line!= search"

View 1 Replies View Related

C++ :: Pointer-based Data Loading From A (text) File

Dec 4, 2013

I have two classes, productListType and buyerListType, that are each basically linked lists. To create the linked list for an object of productListType, I successfully wrote a non-class function createProductList to read the product data from a text file. The class definition for buyerListType has a data member productBoughtRecord that is of type productListType to aggregate the details of the products purchased by a particular buyer during transactions. I decided to make productBoughtRecord a pointer since the contents of this data member would wax and wane over the course of several transactions, depending on the amount and frequency of payments made by the buyer. I have provided a rough sketch of the class below:

class buyerListType
{
public:
setCustomerInfo( ....., productListType* p);
.
.
.
private:
productListType* productBoughtRecord;
.
.
};

I'm similarly trying to write a non-class function createBuyerList to load the record of customers from a text file. How do I determine what the value of the formal parameter p in member function setCustomerInfo is, in order to be able to set the data member productBoughtRecord? take into consideration that an object of class buyerListType would have multiple buyers with varying amounts of products purchased.

View 11 Replies View Related

C/C++ :: Quiz Program Based On Data File Handling

Dec 22, 2014

I'm trying to make a Quiz program based on C++'s Data File Handling capablities. I've attached the code in .txt file and I wonder why I'm getting the error identifier bScience cannot have a type qualifier?

Attached Files QuizPro.txt (9.6 KB)

View 7 Replies View Related

C++ :: Create Matrix Of Data That Add Values Based On Reading Get From DVM

Apr 22, 2012

Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.

The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.

What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?

Here is what I got

Code:
#include <vector>
typedef std::vector<double> Double1D;
typedef std::vector<Double1D> Double2D;
typedef std::vector<Double2D> Double3D;
#define HEIGHT 5
#define WIDTH 3

[Code]....

View 7 Replies View Related

C++ :: Sorting Data Based On Some Metric - Function Pointer Syntax

Nov 20, 2014

I have a piece of code that sorts data based on some metric. The some metric is something I now want to make flexible so I can easily switch between and compare metrics. To do this, I want to pass the function to use as a parameter to the method that does the sorting (and other stuff). However, I'm having problems figuring out the syntax. Also, I think my [temporary] organization of code is violating a lot of basic code design principles.

To make the function pointer passable, I defined the "typename" in the header where the function is located (it is part of a struct, "Data"):

// Below the struct definition of Data
typedef double (Data::*CostF)(unsigned l, double W) const;

The two example functions I want to use are defined in that struct ("Data"):

// Inside the struct definition
inline double someExampleCost(unsigned l, double W) const {
// Returns some basic calculation
}

The function that uses it is part of a different class (that holds a reference to the first class, in case that matters; I feel like I'm doing something odd here, because I'm binding a member function in the definition/passing, but never referencing the object). It looks like this:

// Inside another class ("Foo")
inline void DoSomeStuff(double& ECost, double& TCost, CostF cost) {
// Irrelevant stuff here
std::sort(vector.begin(), vector.end(), [&](unsigned a, unsigned b){
return (*cost)(a, W) < (*cost)(b, W);
});
// More irrelevant stuff here
}

The error shown is "operand of "*" must be a pointer". If I remove the '*':
[code]return cost(A, W) < cost(b, W);

the error becomes: "expression must have a (pointer-to-)function type."

The call to this function is, currently, just in the main function, as I'm just testing before I wrap it into real code. It looks like this:

// In main
Foo bar; // Make an object of the struct that has the "sorting" function
CostF costFunction = &Data::someExampleCost;
// Bind to the Cost function bar.DoSomeStuff(varA, varB, costFunction);

This bit shows no errors by itself. So, my questions:

a) Clearly I'm missing the insight into Function Pointers. I'm comfortable with regular pointer stuff, but I can't wrap my head around FPs, partly due to the awkward syntax.

b) I'm very uncomfortable with the fact that I'm binding a member function of a class, but never try to reference an actual object of that class. This is probably a big part of why it's not working, but I can't seem to bind a function belonging to a specific object. I thought of doing

// In the main again
Data d; // Construct the object, which contains big lookup tables
Foo F(d); // Construct the object, which only holds a reference to a Data object
CostF costFunction = &d.someExampleCost; // Bind to the Cost function of that object

but that doesn't work ("a pointer to a bound function may only be used to call the function").

View 4 Replies View Related

C :: Binary File Write By User Input Then Printing Binary File Data Out

Dec 6, 2013

Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.

Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");

[Code] .....

View 6 Replies View Related

C++ :: Converting Integer To String Based On Digits

Apr 23, 2013

I want to convert the integer into a string.

int x = 693;
char chararr[max];

In my homework, x is unknown. but don't worry, I wont ask for the full code. I just need the part where you change the int into a string/array of char.

I'm thinking in circles from where to start?

View 2 Replies View Related







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