473,394 Members | 1,797 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,394 software developers and data experts.

Read binary

Hi,

I can read in a file with the binaryreader. But how can I get all the bits
("1" and "0") inside my textbox?
(I now get the number 68)

Thanks!
Nov 17 '05 #1
6 1994
One fine day in the middle of the night Arjen wrote in
news:de**********@news6.zwoll1.ov.home.nl:
Hi,

I can read in a file with the binaryreader. But how can I get all the
bits ("1" and "0") inside my textbox?
(I now get the number 68)

You're going to have to parse the number.
First you need to know the size of your value ( 68 appears to be a byte,
so the size would be 8... 8 bits for a byte )

Then you need a mask that you'll walk over your number. Start your mask
at a value of 0x80 and walk down from there. Then create a string to hold
your final binary number. Then walk the mask down the value:
string ConvertHexToBinary( byte myByte /* = 0x44 */ )
{
byte mask = 0x80;
string myBinaryOutput = "";

for( int i = 0; i < 8; i++ )
{
String bit = "";
if( ( myByte & mask ) != 0 )
bit = "1";
else
bit = "0";

myBinaryOutput += bit;
mask >>= 1;
}

return myBinaryOutput;
}

Hope that helps you.
--
Bryan
Nov 17 '05 #2
One fine day in the middle of the night Arjen wrote in
news:de**********@news6.zwoll1.ov.home.nl:
Hi,

I can read in a file with the binaryreader. But how can I get all the
bits ("1" and "0") inside my textbox?
(I now get the number 68)

You're going to have to parse the number.
First you need to know the size of your value ( 68 appears to be a byte,
so the size would be 8... 8 bits for a byte )

Then you need a mask that you'll walk over your number. Start your mask
at a value of 0x80 and walk down from there. Then create a string to hold
your final binary number. Then walk the mask down the value:
string ConvertHexToBinary( byte myByte /* = 0x44 */ )
{
byte mask = 0x80;
string myBinaryOutput = "";

for( int i = 0; i < 8; i++ )
{
String bit = "";
if( ( myByte & mask ) != 0 )
bit = "1";
else
bit = "0";

myBinaryOutput += bit;
mask >>= 1;
}

return myBinaryOutput;
}

Hope that helps you.
--
Bryan
Nov 17 '05 #3
Arjen <bo*****@hotmail.com> wrote:
I can read in a file with the binaryreader. But how can I get all the bits
("1" and "0") inside my textbox?
(I now get the number 68)


So is your problem really just trying to convert an integer into a
binary string? If so, use Convert.ToString(val, 2).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Arjen <bo*****@hotmail.com> wrote:
I can read in a file with the binaryreader. But how can I get all the bits
("1" and "0") inside my textbox?
(I now get the number 68)


So is your problem really just trying to convert an integer into a
binary string? If so, use Convert.ToString(val, 2).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5
I did not know this overload function.

Thanks!
"Jon Skeet [C# MVP]" <sk***@pobox.com> schreef in bericht
news:MP************************@msnews.microsoft.c om...
Arjen <bo*****@hotmail.com> wrote:
I can read in a file with the binaryreader. But how can I get all the
bits
("1" and "0") inside my textbox?
(I now get the number 68)


So is your problem really just trying to convert an integer into a
binary string? If so, use Convert.ToString(val, 2).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #6
I did not know this overload function.

Thanks!
"Jon Skeet [C# MVP]" <sk***@pobox.com> schreef in bericht
news:MP************************@msnews.microsoft.c om...
Arjen <bo*****@hotmail.com> wrote:
I can read in a file with the binaryreader. But how can I get all the
bits
("1" and "0") inside my textbox?
(I now get the number 68)


So is your problem really just trying to convert an integer into a
binary string? If so, use Convert.ToString(val, 2).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #7

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

Similar topics

17
by: Guyon Morée | last post by:
what is the difference? if I open a text file in binary (rb) mode, it doesn't matter... the read() output is the same.
7
by: KantKwitDansin1 | last post by:
I have a file "a.dat" containing 10^4 32 bit binary numbers. I need to read in these numbers and deterimine if they are prime. The primality part I will have to figure out later, but I was...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
1
by: Quinn | last post by:
Hi all, I have some binary files in the following format: text line 1 text line 2 .... text line N end of text single in binary 1 single in binary 2 single N EOF
3
by: utab | last post by:
Dear all, What are the advantages of binary files over text files? I would like to search for a specific value of a variable in an output file, I was doing this lately by the string library...
6
by: =?Utf-8?B?VGhvbWFzWg==?= | last post by:
Hi, Is it possible to read a file in reverse and only get the last 100 bytes in the file without reading the whole file from the begining? I have to get info from files that are in the last 100...
2
by: Marc Ouellette | last post by:
Hi Everyone, I am currently reading Binary files in C++Builder using the code below. Removed some error chacking to make the code simpler to read. std::ifstream fin;...
4
by: Matrixinline | last post by:
Hi All Here is my problem I am using a Unicode project and I tried to read the File like sPath = LPCTSTR; FILE* oFp = _tfopen(sPath,L"r"); while(!feof(oFp))
4
by: =?ISO-8859-1?Q?Hans_M=FCller?= | last post by:
Good morning folks, I cannot read a binary file into a mysql database. Everything I tried did not succeed. What I tried (found from various google lookups...) is this: con =...
6
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: number of Data, Data array Suppose I have...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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
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...

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.