C++ :: String To Int To Byte?
Aug 16, 2014
Right now im creating a program that use xbox inputs and then send out keyboard functions using sendInput();
It works fine, but now im creating a system wich lets the user of the program change the settings in a textfile. Wich will then change what the controllers bindings are.
example, if settings.txt says: Y=button(0xIE)
i want the program to know that when xbox button Y is pressed, execute a sendInput function to the Key: A (0xIE).
The problem is that the virtual keycode (0xIE) i take from the settings.txt is stored as a string (lets say it is stored in string Y_event)and input.ki.wScan has to be of type BYTE. i made a function wich changes string into int. (because input.ki.wScan seems to be fine getting a int?)
int stringToInt(string insert) {
char back[20];
for(unsigned int e=0;e < insert.length();e++) {
back[e]=insert[e];
} return atoi(back);
}
but when i run the code nothing happend...
In the code i have a function wich executes the keypress: void pressbutton(int key, int time)
when i send in the converted string it doesn't work but when i send in: (0xIE) it works.
pressButton(stringToInt(Y_Event),50) // doesn't work
pressButton(0xIE,50) // works
focus on the last part that i wrote.
View 3 Replies
ADVERTISEMENT
Mar 20, 2013
So basically here I have a menu in my C program and if I were to select option 2, I would enter a string up to 30 characters and it would output each block of 16 bytes should be shown which contains a character in the requested string. However, when I compile and run the program and search for the string, nothing happens. what I may be doing wrong?
Code:
else if (select == 2){
printf("Enter a string of up to 30 characters: ");
scanf("%s", &userstr);
//Compares both user's string and file string
for (i = 0; i < size; i++){
if (strcmp (buffer, userstr) !=0){
[Code]...
View 6 Replies
View Related
Apr 25, 2014
I am trying to store each char of a string(string a ="1100") into a byteArray ( byte[] byteArray = new byte[4]. its not showing any error but its storing like below:
byteArray[0] = 49
byteArray[1] = 49
byteArray[2] = 48
byteArray[3] = 48
and what i want is
byteArray[0] = 1
byteArray[1] = 1
byteArray[2] = 0
byteArray[3] = 0
I don't know why but its replacing 1 with 49 and 0 with 48.what am I doing wrong or how to do this?
my code is as below
byte[] byteArray = new byte[4];)/>
int binArrayAdd = 0;
string a ="1100";
foreach (char Character in a)
{
byteArray [binArrayAdd] = Convert.ToByte(Character);
binArrayAdd++;
}
View 4 Replies
View Related
Feb 11, 2014
i need to search for a keyword in a binary(.raw)file and have to extract the characters(until a '&' character is found)that immediately following the keyword .
View 1 Replies
View Related
Jun 6, 2012
I am trying to use C# with C++, two different applications that work together.
In C# it is easy to get a byte array out of a string, by just using Encoding.Default.GetBytes(of-this-string);
I can pass bytes to my C++ program by just writing in the embedded resources. But this won't allow strings, as far as I know it can only be a byte array. C++ reads the embedded resources a LPBYTE.
So I try to send the string or message in byteform.
However the problem in C++ is that there is no Encoding.Default.GetString(xxx)
Would there be any other ways to send a message/sentence in bytearrayform and request it in C++ back to the original string?
View 14 Replies
View Related
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
Oct 15, 2014
Complete the function myitohex so that its converts 8-byte integer to string based hexadecimals.
Ex: printf("0x%s",myitohex(64,hex)); should printout "0x40" on the screen
char *myitohex(uint8_t i, char *result){
???
return result;
}
I wrote:
#include <stdio.h>
#include <stdint.h>
char *myitohex(uint8_t i, char *result){
*result = i + '0';
[Code] ....
0xp gets printed out which is wrong. I think *result = i + '0'; is wrong. What changes should i do on this row ?
View 4 Replies
View Related
Mar 30, 2013
What is the most efficient way to read a bit at a particular position in a byte?
View 13 Replies
View Related
Mar 30, 2013
What is the most efficient way to read a bit at a particular position in a byte?
View 3 Replies
View Related
Mar 16, 2014
I'm trying to get the current time for a game and print that to the games chat window. I'm already injected into the process do I don't think I need ReadProcessMemory.
The value i'm trying to read is the game hours 1-12.
//doesn't work
byte time_hour_get ( void )
{
return *( byte *)0x00B70153; //the address to the memory containing the
}
addMessageToChatWindow((char*)time_hour_get); -> when I call this function it looks like s , . I want it to return the integer value like cheat engine. I used byte when scanning for this address
View 1 Replies
View Related
Apr 13, 2014
Basically it has to do with the byte ordering in a binary buffer vs the typing of a variable used to hold it.
To give you an example, if I have a buffer (say of indefinite length), and a ptr "ptr" pointing to a byte in the buffer (say, C0), such that if I open the buffer in a binary viewer it reads like this: Code: C0 DD FE 1F Such that this is true:
Code:
/*ptr is uint8_t*/
*ptr == 0xC0
Then I do this:
Code:
uint16_t var;
var = *(ptr+1);
I would expect the result to be:
Code: DD FE /*56830*/
Though if I print that out with:
Code:
printf("%u
", var);
It'll print:
Code: 65245 /*(FE DD)*/
Now obviously it's byte swapped, but what is causing that? I'm assuming if I just stream that out to a file byte by byte it'll be fine, so it's something with the 16 bit data type (also have seen this issue with a 32 bit data type, where all 4 are in reverse order). Is there any way to 'fix' it except bit shifts & masks?
View 14 Replies
View Related
Sep 20, 2014
Are locations in the RAM addressed per word or per byte? I am using a 32 bit machine, so I think that it means that on my PC a word would be 4 bytes.
View 11 Replies
View Related
Jun 25, 2014
I basically want to create a save editor application that will enable people to alter various values in the save by clicking on releveant buttons and then also for the editor to auto update the checksum when changes are done.
The save file is in hex so from what I can gather I would need to create a button to open the file using 'open file dialogue' and then read the file into a byte array so that the values can be called at any time when a particular butto is pressed and the application will then seek to the point in the file to make the required changes.
View 3 Replies
View Related
Oct 7, 2014
I have an application that has its own embedded web server. I am trying to add jQuery/Ajax file upload capabilities to the application however, I am running into issues getting the posted file. The jQuery/Ajax portion is similar to this method here. Due to the way the webserver was written (its in a dll and I do not have access to the source), the posted file comes in as a byte[]. If I try to save the byte array directly to file using:
File.WriteAllBytes("path", ByteArray)
I end up with a corrupt file that I cannot open. I believe this is because the byte array also contains the posted file header info (Content-Disposition, name, filename, etc.). If I view the contents of the byte array using:
System.Text.Encoding.Default.GetString(ByteArray)
the header info can be viewed as:
------WebKitFormBoundaryQfPjgEVpjoWgA5JL
Content-Disposition: form-data; name="0"; filename="someimage.png"
Content-Type: image/png
‰PNG
Based on the selected file size and the size of the byte array, the entire file is in the byte array. How can I go about extracting and saving the posted file from the byte array?
View 2 Replies
View Related
Jun 8, 2014
how to use this function:
ftStatus = myFtdiDevice.Read(readData, numBytesAvailable,ref numBytesRead);
to read byte from the serial port.This function is part of the DLL that came with the chip(FT2232D) I am using on my board.I want to use the function to read a byte from the serial port and then send the value to the Graphic user interface.Unfortunately I was unable to get the expected value on my GUI.If I send for instance 40,what I get on the GUI are letters instead of the number 40 or at times the GUI will not even respond.Below are my lines of code I used to read the byte from the serial port:
The following instructions are executed whenever the CHECKBOX is checked
private
void checkBox1_CheckedChanged(object sender, EventArgs e)
{
UInt32 numBytesRead = 0;
[Code].....
View 3 Replies
View Related
Nov 16, 2012
i have a hex code and need to write it in 8051
if the hex code is
"11 22 33 44 55 66 77 88"
"88 77 66 55 44 33 22 11" (hexadecimal)
but the result is
11 22 33 44 55 66 77 88 FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
it is should be
11 22 33 44 55 66 77 88 88 77 66 55 44 33 22 11
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
problem is ...
it can not write second hex code
just only write first hex code
i use serial port , VB6 ,keil C
View 4 Replies
View Related
Feb 26, 2012
Trying to write very simple code to read a 4 byte int from a file.
code:
int tester;
FILE *fp;
fp=fopen("/home/bdluser/skeleton.blx","rb");
fread(&tester,sizeof(int),1,fp);
printf("tested 1 byte read should be 1: %i",tester);
I have tried editing the binary file....it outputs similar large numbers
00000000000000000000000000000001 outputs 808464432
0x00000001 outputs 808482864
0x10000000 outputs 808548400
10000000000000000000000000000000 outputs 808464433