C++ :: The Value Of 8 Bytes For Unsigned Integers

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


ADVERTISEMENT

C/C++ :: Reverse Order Of Bytes Unsigned Char Array?

Dec 1, 2014

I need fastest method to reverse order of bytes in my char array.

For example i have:

unsigned char buf[8];
// consider data stored in buf is 88 77 66 55 44 33 22 11
// how to reverse it to: 11 22 33 44 55 66 77 88
// currently i can do it by equal assignment , i make another buf like:
unsigned char buf_ok[8];

[Code] ....

// This does reverse the bytes as i want but its very slow , i am looking for fast method ..

View 3 Replies View Related

C :: Finding Positive / Negative Integers Unsigned Can Hold

Jan 25, 2013

Consider a new data type, the mikesint, which can hold 9 bits.

(a) What is the largest integer that an unsigned mikesint can hold?
(b) What is the largest positive integer that a signed mikesint can hold?
(c) What is the largest negative integer that a signed mikesint can hold?

Not sure how to determine this. I'm stuck.

View 5 Replies View Related

C :: Radix Sort Function To Sort Array Of 64 Bit Unsigned Integers

Aug 19, 2013

Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.

Code:
typedef unsigned long long UI64;
typedef unsigned long long *PUI64;
PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) {
size_t mIndex[8][256] = {0};
/* index matrix */
PUI64 pDst, pSrc, pTmp;
size_t i,j,m,n;
UI64 u;

[Code]....

View 9 Replies View Related

C/C++ :: Accommodate Double-size 8 Bytes In 4 Bytes Pointer In 32bit System?

Mar 15, 2015

how to accommodate double-size:8 bytes in 4 bytes pointer in 32bit system.

View 1 Replies View Related

C++ :: Why Address Of Object Is 6 Bytes And Not 8 Bytes On 64 Bit Linux

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

C++ :: Making Function To Read Unsigned Integer Into Variable Of Type Unsigned Short Int

Apr 3, 2014

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 Related

C++ :: Copying Two Unsigned Char Into Unsigned Char

Mar 30, 2014

unsigned char key[32];
139 unsigned char rfseed[32];
173 f = fopen("/dev/urandom","rb");
174 fread(key,1,32,f);
175 fread(rfseed,1,32,f);

I am having problems copying outputs of the above code into other unsigned char other[32]. I need to keep the output of dev/urandom for backup. But, when I try to assign the values by memcpy(other, key, 32), the values do not match. The same problem happens by assigning values index by index in a loop.

View 2 Replies View Related

C++ :: Read Set Of Integers Then Find And Print Sum Of Even And Odd Integers

Apr 21, 2014

I'm a beginner at c++ and I need to write a program that reads a set of integers and then finds and prints the sum of the even and odd integers. The program cannot tell the user how many integers to enter. I need to have separate totals for the even and odd numbers. what would I need to use so that I can read whatever number of values the user inputs and get the sum of even and odd?

View 2 Replies View Related

C :: How To Split Int Into 2 Bytes

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

C/C++ :: How Many Bytes / Bit In A String

Nov 2, 2012

How many bytes in a string ....

How many bit in a string ...

View 3 Replies View Related

C++ :: Reading Bytes Without Bit Loss

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

C++ :: Printing Out Bytes Of A File

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

C++ :: Streaming Bytes Into Integer

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

C++ :: How To Convert Bytes To ASCII

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

C :: Checking How Many Bytes Are Remaining In A File?

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

C :: How To Read In Nine Bytes And Check To See If There Is A Match

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

C :: Program To Convert Bits To Bytes

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

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 View Related

C++ :: How To Create Character Array That Has 128 Bytes

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

C++ :: Deleting Certain Bytes From Binary File?

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

C# :: How To Combine Two Bytes In Int32 To Get Original Value

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

C++ :: How To Read Single Bytes From Wifstream

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

C++ :: Write Process Memory Bytes

Apr 8, 2014

Writing bytes to external process to remove a detour that the program does

this is what im trying it fails

HANDLE Handle = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessId);

BYTE btLdrLoadDll[] = { 0x8B, 0xFF, 0x55, 0x8B, 0xEC };

if (!WriteProcessMemory(Handle, (BYTE*)((DWORD)GetProcAddress(GetModuleHandle("ntdll.dll"), "LdrLoadDll")), &btLdrLoadDll, sizeof(btLdrLoadDll), NULL)) {
CloseHandle(Handle);
std::cout << "
Failed to write Bytes to memory. Press enter to exit.";

[Code] ....

an also using the right address like this fails

WriteProcessMemory(Handle, (BYTE*)0x77C64F9F, &btLdrLoadDll, sizeof(btLdrLoadDll), NULL)

View 8 Replies View Related

C/C++ :: Reading Hexadecimal Bytes From A File?

Jan 19, 2014

#include <stdio.h>
#include <stdlib.h>
int main(int argc, int * argv) {
   char buffer[16];
   FILE *fp;
   unsigned long long test;
   unsigned char key[16];
   fp = fopen("D:key.txt","r");

[code].....

i searched for a code for reading bytes from a file and i found this one but when i run the program, it doesn't return the bytes written in the file, it returns another bytes / what is the problem?

View 3 Replies View Related

C/C++ :: Read Bytes From A Data File

Dec 5, 2014

I am a member of a group still developing the Microprose European Air War game. We have the source code and permission to do this. As the code dates back to 1998 I use Visual Studio 2006.

I have written many programs in Visual basic, and have the following one to read the airbase value in the "targets.dat" file. The file has a four byte header containing the number of tatgets, and a 32 byte data block containing the data for each target.

Private Sub Command1_Click()
List1.Clear
Dim nt As Long
Dim a4() As Long  
Open App.Path & " argets.dat" For Binary Access Read As 1
'read and display the number of targets  

[Code] ....

Despite many attempts I cannot write the C equivalent of this code into the eaw.exe source. All I really need to know is how to open the 'targets.dat' file and how to get the value of a byte (or integer, or long) at a given position as in the "Get #1, k, a4(n)" line.

View 1 Replies View Related







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