473,493 Members | 4,319 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 2212
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
4435
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
41768
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
14576
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
294
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
3354
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
19191
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
12906
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
4907
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
6259
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
7157
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
7192
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
6862
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...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4579
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
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.