C++ :: Breaking A Float Into Bytes For Binary I/O
Aug 12, 2013
I'd like to know how I could break a float into individual bytes for binary use.
Sounds simple, but it seems as though the compiler doesn't realize everything is just a series of bytes.
View 8 Replies
ADVERTISEMENT
May 26, 2013
How to delete certain bytes from middle of a binary file?
Those bytes are in fact of a struct.
One approach I found was to re-write the whole data except the struct I want to delete. But may be its not good one if file size is in gb and I will have to write complete data again.
View 1 Replies
View Related
Aug 20, 2014
How I write a 0s or 1s to binary file in bits not in bytes how can i do that ???
View 2 Replies
View Related
Mar 15, 2015
how to accommodate double-size:8 bytes in 4 bytes pointer in 32bit system.
View 1 Replies
View Related
Mar 24, 2013
Code:
int i12 = 1001;
cout << i12 << " " << &i12 << endl;
gives the result: 0x7fff0d065098
It's 6 bytes, but I'd expect the address to be 8 bytes on my 64 bit machine. I am using Ubuntu 12.04, GNU compiler.
So, why the address is 6 bytes and not 8 bytes?
View 10 Replies
View Related
Feb 26, 2015
i just want to break the loop when user hit ENTER.But after that programm is stil working, i don't know why, becouse i have a code just like in book, i spend a lot of time with it.
int getinfo(student pa[], int n){
cout << "START" << endl;
int i = 0;
for(i; i < n; i++) {
cout << "Studetn name";
char name[SLEN];
[code].....
View 2 Replies
View Related
Mar 14, 2014
Code:
while(x==1){
for (i=0;i<j;i++)
{if (word1[i] == word2[i])
{prefix[i]= word2[i];
counter++;}
else
x=2;}
Basically after the 3rd run of the for loop, it encounters a contradiction. I want it to exit right there and then. Instead it continues to run the for loop. What can I do?
View 4 Replies
View Related
May 16, 2012
I'm get input from the user and then storing it in "s " and then trying make tokens, but it is not working, and after making tokens I'm counting them. Here is My Code
Code:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(){
string s;
[Code] ....
Here is my Output
Enter text:
Entered Text is: This is String
token 1: This
token 2: is
token 3: String
token 4:
Number of tokens: 3
The problem is that i want to store the first two strings "This" and "is" into two variables and how to remove token 4: which is unnecessary .
View 5 Replies
View Related
May 16, 2014
I know that you're allowed to use a char pointer to access any object but are you allowed to inspect a char array with a different type, say an unsigned integer without breaking the strict aliasing rule? My understanding is that it's not legal and could lead to trouble with trap representations but I just wanted to make sure.
View 4 Replies
View Related
Feb 6, 2014
I have function that returns historical data. I can access it, using file name. If I use file name, it reads that file and saves it to dictionary, so that in the future, if historical data is required for the same file, it does not read it again (it's lazy loading). If no file is supplied to the function, it tries to read file which is given in app settings.
However, for unit testing, I do not want to read any file. Instead, I want it to use small sample of hardcoded historical data. In order to do that, I think, I need to introduce interface to it. Then I can use some IoC to choose between different implementation for unit testing purpose and ordinary launch of application.
Function to get history is given as follows:
public static class Auxiliary
{
private static Dictionary<string, MyData> _myData;
public static MyData GetData(string fileName = null)
{
// ...
}
}
I have created default Unit Test project with Visual Studio so, as far as I know, by default it uses MSTest as test runner and MSUnit as unit testing framework but it does not have any IoC container so I should manage NuGet packages for solution and install Unity.
As far as I know, MSUnit (aka Moles) can unit test static methods (it's unconstrained isolation framework, like Typemock Isolator, unlike NUnit) but still many people suggest not to use any static methods for unit testing.
Should I use shim or stub [URL] Stubs should be used for faking external dependencies and here it is not external library, but my own code.
View 1 Replies
View Related
Feb 9, 2015
I'm trying to make sure my code is written in smaller modules, so my first step is to create my initialization process in and external file to load the necessary data from external sources and set up things like the content of drop down list boxes.
My first attempt failed to give me access to the combobox items add function so I moved that code back into the form1.h file:
Code:
public:
Form1(void) {
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
void AddDate(char *date, int ID)
{
this->comboBox1->Items->Add("line 1");
}
It compiles fine, but the call to it in my Initialize.cpp file
Code:
MarketView::Form1::AddDate("abs",1);
Gives error C2352: 'MarketView::Form1::AddDate' : illegal call of non-static member function
OK, so I change "void AddDate" to "static void AddDate" and now get the error that "static member functions do not have 'this' pointers" so I go back to the "MarketView::Form1::comboBox1" situation where there is no legal syntax after "Box1 to get me to Items->Add
I've been an old fashion programmer for over 47 years. It seems as is the concept of programming computers has changed from the concepts of logic to memorization of complex syntax.
There has to be a simple answer to do this other than to write thousands of lines of code in one Form1.h file. I refuse to believe that the new programming concepts will not allow you to write code in smaller more manageable modules.
What is the proper syntax for breaking up the larger file into more manageable chucks?
View 12 Replies
View Related
Nov 20, 2013
I can do the folowing:
float var1 ;
var1 = 9.12345 ;
printf("%.2f",var1) ;
the output will be 9.12. What if I wanted to save that as another separate float with displaying it on screen?
View 1 Replies
View Related
Jun 8, 2014
#include <iostream>
#include <string.h>
#include <sstream>
[Code]....
View 1 Replies
View Related
Oct 23, 2013
Im using some motors which run off PWM pins.Theres a High byte and Loq byte register (PWMH,PWML).I have an int which i need to put into these registers but i dont know how???so for example
int:84 -> PWMH=0x00 , PWML=0x54
int:310 -> PWMH=0x01 , PWML=0x36
int:11588 -> PWMH=0x2D , PWML=0x44
View 2 Replies
View Related
Nov 2, 2012
How many bytes in a string ....
How many bit in a string ...
View 3 Replies
View Related
Jan 26, 2014
I'm confused about the actual value of 8 bytes for unsigned integers.
The below code suggests the value is 13217906525252912201:
#include <stdio.h>
#include <inttypes.h>
typedef uint64_t byte_int_t;
int main(void){
byte_int_t t;
printf("%" PRIu64 "
", t);
}
./runprogram
13217906525252912201
However, when I use a calculator, I get a different value: 2^64= 1.8446744e+19
So I was wondering is this really 8 bytes? So I try below test and it produces 8, as expected:
#include <stdio.h>
#include <inttypes.h>
typedef uint64_t byte_int_t;
int main(void) {
byte_int_t t;
printf("%u
", sizeof(t));
return 0;
}
So why does C and my calculator provide two different results?
View 1 Replies
View Related
Apr 13, 2013
I need to read repeatedly data from a MPEG2 file to the buffer of 188 bytes and analyse data bit by bit.
I have the problem with correct bytes reading from file. In my code listed below I have two methods for that.
First one is lossing this bytes which in hex_base mode have 0 at the begining, eg: 03, 0F, etc.
The second method based on read function which need to have buffer as a char (lenght > 1 byte). Because of that I receive different values from that from file in some cases.
How can I properly read such file?
Code:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
int main() {
fstream plik_in;
[Code] .....
View 2 Replies
View Related
Sep 4, 2012
I am encoding some information in a binary file, and I want to check what I am doing by printing out all the bytes that represent the file.
This is being done by opening a pointer to the file with fopen, reading in each byte of data as a char, and then writing this char to the screen.
I have some image files (e.g. "image.jpg"), whose structure I know, so that I can test my program.
When I print out the chars, they are initially correct, and follow the structure of the file as expected.
However, after about 40 bytes, I find that every subsequent character is ' ' i.e. a blank character.
I then created a CharToBin function, which allows me to print out the actual bits in the char. When doing this, it shows that all the bits are 1 for the characters. i.e. most of the file is represented by 1's, which is clearly not correct.
This happens on all the image files I have tested, and furthermore, on several other non-image files. They all start printing out ' ' after a while. However, all these files are fine and not corrupted, e.g. the image files display correctly.
Code:
#include <fstream>
#include <iostream>
#include <sstring>
#include <string>
#include <stdio.h>
using namespace std;
string CharToBin(char ch) {
bool bits[8];
for (int i = 0; i < 8; i++)
[Code] ....
View 6 Replies
View Related
Sep 4, 2012
I have a FILE stream, and I want to create a function that streams a specified number of bytes (up to four bytes) and returns the value of this, as an integar.
For example, supposing that my FILE has the following data, in hex: 74 C8 02 33 F2 7B....... I then want to stream three bytes and store this as an integar. So, I want to stream "04 08 02". The data stored in the integar should then be "00 74 C8 02", because I have not streamed anything into the first byte. By converting the hex to dec, the integar should then be of the value 7653378 (if it is unsigned).
To try to achieve this, I have written the following function. I create an integar and initialise it to zero, then take each byte from the stream, and OR it with my integar. Then, I shift the integar left by 8, and read the next byte, and so on.
The problem is, when I convert "c" to "c_int", it adds on a load of 1's to the left of the "c" data. This then means that the OR comparison changes all those bits in my integar to 1.
How to solve this? I am also wondering whether there is a much more simple way of doing this, rather than having to write my own function....
Code:
int StreamFileToInt(FILE *fp, int num_bytes) {
char c;
int c_int;
int x = 0x0000;
for (int i = 0; i < num_bytes; i++) {
[Code] ....
View 4 Replies
View Related
Feb 7, 2014
How can I convert bytes to ASCII?, I read wikipedia about UTF-8 and I understood a little bit about add or split bytes to change the value.
Now I have those bytes
0xC7 0xE6 0xC2 0x91 0x93 0x7B 0xCE 0x01
And I found a program (DCode) that convert to 64 bits little-endian, supposedly those bytes in ASCII is this.
lun, 08 julio 2013 04:28:17 UTC <---
View 3 Replies
View Related
Feb 22, 2013
while bytesremaining >=8 do something;
if bytesremaing <8 then something else .
I am new and don't know how to code for this.
View 2 Replies
View Related
Feb 22, 2013
and see if the first three match a list then read in three more behind those that were left and perform a similar test on them and keep going?
View 8 Replies
View Related
May 13, 2013
I made this program to convert bits to bytes, because I'm so sick of seeing ISP's advertise speeds in megabits, which I consider an intentional attempt to decieve :P And I think I've finally understood how the return value of scanf works since the last time I posted here, so my program can check to see if an integer was entered before processing the input, but I'm stuck on how to make the whole program start over if an integer is not entered. I have a hunch it would involve a loop, but I can't figure out how to make the program start over at "How many mb do you need converted?" if an integer is not entered into scanf..Here is the code I have so far:
Code:
#include <stdio.h>
int main () {
int b, mb, kb, Byte, kB, mB, gB;
char term;
}
[code]....
and my program makes the assumption for now at least, that mb will be inputted because that's the unit of measurement that i usually see advertised, and i didn't bother making an if statement to print a conversion in terms of gigabytes because i've never heard of a connection that fast :P
View 5 Replies
View Related
Sep 23, 2014
m_sName-- character array shall be 128 bytes
How do i create a character array that has 128 bytes?
View 1 Replies
View Related
Jan 6, 2015
how to combine two bytes (each byte is 8 bits wide) in order to get the original value. I am displaying values(from 0 to 500)sent from my microcontroller on the GUI.I can successfully display values from 0 to 255 as this requires just sending a byte. However sending values from 256 to 500 requires sending two bytes. The problem I am having is that I was unable to re-combine the received two bytes in order to get the original value. Below are my lines of code:
int main( void ) // this is the main function inside the microcontroller {
sei();
USI_TWI_Master_Initialise();
Spi_Master_Init();
while(1) // I am using this loop to send 500(111110100) {
Transmitt_Receive(244);//this function sends LOW BYTE of 500(11110100)
_delay_ms(1000);
[code]....
When I combined the two bytes using the above arrangements, instead of getting 500 my GUI displayed 62708.I got the same result when I used BitConverter.
value3 = BitConverter.ToInt32(val,0);
View 7 Replies
View Related
Apr 27, 2013
I want to read a single byte from a wifstream. With an ifstream I would use read(), but given that the char type for an wifstream is wchar_t (2 bytes), this is also being used by read(), so how can I read a single byte from such a stream?
View 3 Replies
View Related