473,473 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

convert int to store in binary file in 1byte

Hi,
Could anyone help me out on this.
I'm trying to store an unsinged int that will at most use 1byte into a
binary file but to no avail.
could anyone help me out on this? thanks in advance

Apr 2 '06 #1
4 2211
yc*****@gmail.com writes:
Could anyone help me out on this.
I'm trying to store an unsinged int that will at most use 1byte into a
binary file but to no avail.
could anyone help me out on this? thanks in advance


unsigned char is an unsigned integer type that's exactly 1 byte in
size.

You posted the same question three times. (That seems to happen a lot
with groups.google.com; I'm not sure why.)

<http://cfaj.freeshell.org/google/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 2 '06 #2
yc*****@gmail.com schrieb:
Hi,
Could anyone help me out on this.
I'm trying to store an unsinged int that will at most use 1byte into a
binary file but to no avail.
could anyone help me out on this? thanks in advance


Please stop your rapid reposting -- your message did come through
the first time.

If you have
unsigned int value;
and
value <= UCHAR_MAX;
is always true, then you can just assign value to an unsigned
char variable and write this one to the file
(sizeof (unsigned char) is always 1 [byte]).

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Apr 2 '06 #3
On Sun, 02 Apr 2006 09:08:29 +0200, Michael Mair wrote:
yc*****@gmail.com schrieb:
Hi,
Could anyone help me out on this.
I'm trying to store an unsinged int that will at most use 1byte into a
binary file but to no avail.
could anyone help me out on this? thanks in advance


Please stop your rapid reposting -- your message did come through
the first time.

If you have
unsigned int value;
and
value <= UCHAR_MAX;
is always true, then you can just assign value to an unsigned
char variable and write this one to the file
(sizeof (unsigned char) is always 1 [byte]).


.... indeed, but would not fputc(value, fp) be even simpler?

--
Ben.
Apr 2 '06 #4
Ben Bacarisse schrieb:
On Sun, 02 Apr 2006 09:08:29 +0200, Michael Mair wrote:
yc*****@gmail.com schrieb:
Hi,
Could anyone help me out on this.
I'm trying to store an unsinged int that will at most use 1byte into a
binary file but to no avail.
could anyone help me out on this? thanks in advance


Please stop your rapid reposting -- your message did come through
the first time.

If you have
unsigned int value;
and
value <= UCHAR_MAX;
is always true, then you can just assign value to an unsigned
char variable and write this one to the file
(sizeof (unsigned char) is always 1 [byte]).


... indeed, but would not fputc(value, fp) be even simpler?


Yes, as long as INT_MAX >= UCHAR_MAX; IOW, in nearly all cases :-)

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Apr 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
13
by: Hako | last post by:
I try this command: >>> import string >>> string.atoi('78',16) 120 this is 120 not 4E. Someone can tell me how to convert a decimal number to hex number? Can print A, B, C,DEF. Thank you.
5
by: Trammel | last post by:
Hi, I have a vb.net program made to grab screenshots and then store them in image objects. The image is displayed in a pictureBox atm but I want to store the data in a String only. (Without...
0
by: ycliuwz | last post by:
Hi, Could anyone help me out on this. I'm trying to store an unsinged int that will at most use 1byte into a binary file but to no avail. could anyone help me out on this? thanks in advance
5
by: lawrence k | last post by:
I'm a little weak on my basic I/O. Help me out please. Is it right to say that I can just open any file with file(), get it as a string, and then store in a MySql database, in, say, a MediumText...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
5
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I am having a problem converting string to binary and I am hoping someone can help me out I have a sql query that does an update that updates a binary field calles password ...
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
7
by: chelle2100 | last post by:
hi... i need to write a converter to convert the text file to a binary file with the following file format... CharacterCount:Unsigned Char(This stores the number of characters that is in the file)...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.