473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2206
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.