Click here to Skip to main content
15,886,258 members
Everything / Binary

Binary

binary

Great Reads

by Christ Kennedy
A graphically bouncy and colorful version of the popular numbers tile-sliding game
by honey the codewitch
BinaryReader and BinaryWriter can be used to parse or write binary files more easily and in a portable manner
by Member 13376231
An overview of a tricky binary collision example when there are multiple definitions of symbols in linked binaries
by PIEBALDconsult
I wasn't going to publish this version, but I just used it a second time, so maybe someone else will need it too. This is very much like the second version above except that it uses a non-generic IList. Today, I used this to find and insert TreeNodes in a TreeNodeCollection, yesterday I used it...

Latest Articles

by Jovibor
Library for parsing internal structures of PE32/PE32+ binary files.
by Member 13376231
An overview of a tricky binary collision example when there are multiple definitions of symbols in linked binaries
by Christ Kennedy
A graphically bouncy and colorful version of the popular numbers tile-sliding game
by honey the codewitch
BinaryReader and BinaryWriter can be used to parse or write binary files more easily and in a portable manner

All Articles

Sort by Score

Binary 

6 Oct 2020 by Christ Kennedy
A graphically bouncy and colorful version of the popular numbers tile-sliding game
4 Feb 2013 by CPallini
If you need to change the content of a file (that is overwrite it) then you have to:Read the file content into memory.Modify memory content.Write back modified memory content to the original file.You may use the C++ fstream to read/write a binary file, see, for instance Input/Output with...
20 Feb 2013 by Sergey Alexandrovich Kryukov
You have everything you need with std::ofstream, std::ifstream and std::fstream:http://www.cplusplus.com/doc/tutorial/files/[^].I hope you also know bitwise arithmetic and bitwise operators. If not, lean them. Streams give you per-byte access, so you can read a byte, extract individual...
4 Aug 2013 by OriginalGriff
This is your homework, so I'll give you a "short" version:1) Mechanically. It's closer to a calculator than a computer. How does an abacus add and subtract?2) No. Google "Pingala"3) Machine code. Entered via on/off switches on the front panel of computers. (Still in use in the early...
12 Nov 2015 by CPallini
Your program actually does save in binary format (if you write plain text in a binary file the it will contain, well, plain text). You may see strange output (you call it 'binary') depending on the application you use to inspect the file.
2 Apr 2016 by Richard MacCutchan
See Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)[^] for full details on file I/O.
31 May 2011 by CPallini
If you are using System.Drawing then you may create a bitmap of the same size then use the SetPixel method (or, if performance matters, the LockBits one, see Bitmap.Lockbits[^] at MSDN). The straighforward transformation of the RGBA components is the simple multiplication by 64 85 (sorry 64 was...
31 May 2011 by Sergey Alexandrovich Kryukov
First rule. Do not use GetPixel/SetPixel: it's too slow! You can get acceptable performance only when you do it all at once.Do the following. Create empty bitmap of the class System.Drawing.Bitmap and use System.Drawing.Bitmap.LockBits method. For pixelFormat, use...
19 Sep 2011 by OriginalGriff
If only there was a tool which let you type questions into the internet, and it would provide answers?Yes, that certainly would be useful!Pity, really, that it doesn't exist.What's that? Are you sure? Oh, right.My cat just informed me that it does exist! And he is only 11 weeks...
15 Feb 2012 by Sergey Alexandrovich Kryukov
I'm not sure you can save too much of CPU time on custom marshaling compared to a binary serializer.However, you can potentially squeeze some extra performance, mostly by reducing redundancy. You can do it if you build you application-level protocol based on specialized and relatively rigid...
27 Sep 2012 by Sergey Alexandrovich Kryukov
The question makes no sense. Everything is "binary", including your original audio file.[EDIT]After OP's (incomplete) clarification:I can only guess that you need to represent the waveform and do some image recognition, but it all depends on what you have and what you want —...
21 Jan 2013 by OriginalGriff
There are a huge number of ways: the simplest is:Dim data As Byte() = File.ReadAllBytes("D:\Temp\MyVideo.mp4")data(0) = CByte(&Hff)File.WriteAllBytes("D:\Temp\MyModifiedVideo.mp4", bytes)But don't expect the file to work if you do exactly that! :laugh:
3 Feb 2013 by Matthew Faithfull
All computer languages 'work with binary' or rather wouldn't work without it. If you're going to be doing bit 'twiddling', for example writing your own ieee754 floating point implementation then 'C' is the traditional language of choice but these days C++ is a better option in my opinion or of...
4 Feb 2013 by Emilio Garavaglia
Using the C++ standard library, you have to construct (or open) an std::fstream giving the appropriate mode flags (ios_base::binary)See http://en.cppreference.com/w/cpp/io/basic_fstream/basic_fstream[^]After that, use only unformatted i/o methods (like istream::read and ostream::write)...
6 Feb 2013 by H.Brydon
Pretty simple if you only have 2 input and 2 output values.char Compress(char in){ if(68 == in) return 1; // 01000100 -> 1 if(66 == in) return 0; // 01000010 -> 0 return -1; // invalid}char Decompress(char in){ if(1 == in) return 68; // 1 -> 01000100...
4 Aug 2013 by Richard MacCutchan
All of these questions can be found by doing some basic research, and none of them have anything to do with C++. Get hold of a copy of a book or use Google to search for "history of computers".Briefly:Use GoogleBinary has existed since the beginning of the universe. And early digital...
1 Jan 2015 by OriginalGriff
Yes - and No.Yes, you can develop a very large program purely in binary - it's how we started in this game and the first operating systems and everything else were written that way.But...it's slow. Very slow. That's why one of the first things written in binary was a basic assembler, to...
9 Jun 2015 by OriginalGriff
Don't do it like that!Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.Surprisingly, that'll also cure your problem...When you concatenate...
9 Jun 2015 by Richard Deeming
Your code is vulnerable to SQL Injection[^].NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.A side-effect of fixing this serious security vulnerability in your code will be that you will also fix your problem:public string InsertUpload(string...
10 Nov 2015 by OriginalGriff
It's e): Do your own homework.We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial...
9 Mar 2016 by OriginalGriff
So stop converting it to a number and start by validating the string.Create a bool value "hasPoint", and set it to false.loop through the input string, examining each character in turn.If it is a '0' or a '1', then it's fine.if it's a '.', then check "hasPoint" if it's false, then set it...
2 Sep 2016 by OriginalGriff
To be honest, if you can't work out how a hex editor shows data, then you're probably trying to take on a task that is way beyond your current skill set: the picture shows a "standard" hex editor with hex byte view on the left (where every byte is displayed separately as a two digit hexadecimal...
25 Aug 2019 by RickZeeland
Here is a tutorial: Binary trees - Learn C - Free Interactive C Tutorial[^] And here is a nice explanation: binary-search-trees-explained-5a2eeb1a9e8b[^]
20 Jan 2022 by M Imran Ansari
Try the following link: Python program to print the binary value of the numbers from 1 to N - GeeksforGeeks[^]
11 Jul 2022 by CPallini
Here, for instance, you may find a description (and an example) of such a method: Binary Calculator[^].
9 Mar 2015 by phil.o
If you start from the hexadecimal representation of the value, and you want to work with it, you have to do it in several steps:- First, translate this hexadecimal string representation of a byte array into a byte array- Second, pass this byte array to the GetString() method of the...
8 Aug 2011 by jetskij16
I have been looking for a couple days now and apparently I am not entering the correct search terms to find what I am looking for, so thank you in advance for any help.I am receiving a string that is encoded from an external datasource so I can't change how I'm receiving the data. My...
8 Aug 2011 by jetskij16
string data = "544d444e5036";byte[] tempArray = new byte[data.Length / 2];for (int i = 0; i
28 Sep 2011 by Stefan_Lang
At a glance, I'd say you should change void add(HeapNode * child) { // if the new value is bigger than this value if(child->value > value)to void add(HeapNode * child) { // if the new value is smaller than this value if(child->value
19 Nov 2011 by T0mii
fixed it, i was over thinking it, cause i just need to delete the largest number in my tree and that wont have a right childe, and then i only have to replace it with the left childe if he got one and delete it, it works perfect, ty everyone who helped me, trough this project.Here is the...
10 Jan 2012 by Richard MacCutchan
Why are you messing about with the data in this way? You receive a stream of bytes from the network so all you need to do is write that stream (whatever length you receive) to the disk. Don't try converting to a string (what does that achieve?) and don't write four bytes as an int.
6 Feb 2012 by Corporal Agarn
Google is our friend.Have you tried CAST(bin AS VARCHAR(50)) where bin is your column. Note if this is encrypted you will not be able to do this.
15 Feb 2012 by Muhammad Idrees GS
Hi,I am developing a client/server application in c#.net. Now I am going to pick the communication mechanism use in client/server packets. I want to know, what will be the best format for sending and receiving data on sockets. Xml serialize or Binary serialize(i am using Marshalling,...
15 Feb 2012 by Mehdi Gholam
Check out my article fastJSON[^] Which is faster than XML and Binary serialization and is as robust as Binary for polymorphic data.
4 Mar 2012 by Mohammad A Rahman
Hope it helps,How to store and fetch binary data into a file stream column[^]:)
17 May 2012 by Maciej Los
Few useful links:Storing and Retrieving Images from SQL Server using Microsoft .NET[^]http://forums.asp.net/t/1096999.aspx[^]http://www.dotnetspider.com/forum/32610-Save-Image-into-database.aspx[^]http://www.aspnettutorials.com/tutorials/database/Save-Img-ToDB-Csharp.aspx[^]
17 May 2012 by OriginalGriff
Use a parametrized query (you should be anyway to avoid SQL Injection attacks). This code inserts the Thumbnail image as a byte array: using (SqlConnection con = new SqlConnection(GenericData.DBConnection)) { con.Open(); byte[]...
11 Jun 2012 by Jαved
Hi,Go through this link it explains everything-Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]
22 Aug 2012 by Kenneth Haugland
There are a couple of good articles about it on the codeproject site:http://www.codeproject.com/search.aspx?q=binary+search&x=13&y=9&sbo=kw[^]If you cant find anything here you should have a look at Google[^]. In the future you should try it yourself first, before you ask :)
22 Aug 2012 by ridoy
http://www.dotnetperls.com/array-binarysearch[^]
1 Nov 2012 by OriginalGriff
First off, that isn't a good question.It contains no detail of what you want, and makes no real sense.Secondly, that isn't how it works. The idea is: You try to do it, you get stuck, you ask for help.Just asking for code will not please anyone, and will result in you not getting...
1 Nov 2012 by OriginalGriff
Binary, octal and hex are all the same in this context - you just need to convert the string to bytes:string s = "Hello!";byte[] bytes = System.Text.Encoding.ASCII.GetBytes(s);
2 Nov 2012 by Shanalal Kasim
Try: SqlConnection connection = new SqlConnection ("..."); connection.Open (); // Select binary data from db SqlCommand command = new SqlCommand ("select PdfFile from Table", connection); byte[] buffer = (byte[])...
14 Jan 2013 by Andreas Gieriet
In my first solution to your question I took your question too literal: you ask for a floating point solution.Reading now your expected result shows that you in fact talk about a fixed point problem.A fix point approach places the separation between integral part and the fraction part at a...
20 Jan 2013 by Ashok19r91d
Function CompressText (ByVal TextToCompress as String) As IntegerIf TextToCompress = "01000100" Then Return 1If TextToCompress = "01000010" Then Return 0End FunctionFunction DeCompressText (ByVal TextToDeCompress as String) As StringIf TextToDeCompress = 1 Then Return "01000100"...
22 Jan 2013 by Sergey Alexandrovich Kryukov
It can be done on one of several different levels of networking, remoting or WCF.Please see my overview of these approaches in my past solutions:how i can send byte[] to other pc[^],Communication b/w two Windows applications on LAN.[^].—SA
19 Feb 2013 by Arun1_m1
create table #bitoprt(id int identity(1,1),bag bit,tapee bit,band bit,knife bit,guitar bit,watch bit,umbrella bit,hammer bit)insert into #bitoprtvalues(0, 1, 1, 0, 1, 1, 1, 0), ( 0, 1, 1, 0, 1, 1, 0, 0), ( 0, 1, 1, 0, 0, 0, 0, 0)select (bt.bag...
2 May 2013 by Richard MacCutchan
Try iTextSharp[^].
18 Jun 2013 by OriginalGriff
The first thing you want to do if you want a hex editor is to stop using strings: use byte values at all times - strings contain unicode characters which are of variable length, and do not have to be 8 bits.Read your file as bytes, store it as bytes and convert it to ASCII values for display...
17 Dec 2013 by CPallini
Microsoft genlty provides an article on the argument: "An Extensive Examination of Data Structures Using C# 2.0 - Part 3: Binary Trees and BSTs"[^].
6 May 2014 by CPallini
Some insight here: "comparison operator values C++" at Stack Overflow[^].
16 Oct 2014 by Nihar Ranjan Sahu
Try this:byte[] toBytes = Encoding.ASCII.GetBytes(somestring);
8 Nov 2014 by Manas Bhardwaj
Did they block Google [^]at your place? Look at the links to start...
1 Dec 2014 by Maciej Los
Have a look at past answers of Sergey Alexandrovich Kryukov[^]. He explain very well, how to resolve this kind of errors.
8 Dec 2014 by enhzflep
It's actually pretty easy, if one is vaguely familiar with image-based programming tasks.I left a description of the file format in a comment above, though this can be seen from the code below.I first tried to create the new image and then use GDI+ to save it as a PNG complete with 16...
8 Mar 2015 by Praneet Nadkar
Hi,Depending on which encoding was used, use the following code:byte[] binaryString = (byte[])reader[1];// if the original encoding was ASCIIstring ascii = Encoding.ASCII.GetString(binaryString);// if the original encoding was UTF-8string utf =...
8 Apr 2015 by OriginalGriff
Try:using (SqlConnection con = new SqlConnection(strConnect)) { con.Open(); using (SqlCommand cmd = new SqlCommand("SELECT myPDFData FROM myTable", con)) { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) ...
5 Jun 2015 by Sergey Alexandrovich Kryukov
Please see my comment to the question, where I already tried to explain to you the essence of things. Due to the complicated character of the problem, I certainly cannot give you the whole solution; I only can tell you what to start with: you have to start with finding out what you are dealing...
8 Jun 2015 by Sergey Alexandrovich Kryukov
I have no idea what makes you thinking that you can identify the source of some image by capturing some specific pattern. I don't think so. And of course the expression "hex pattern" is absurd: "decimal" or "hexadecimal" is just the artifact of string representation of some numeric data in...
12 Nov 2015 by Richard MacCutchan
If you inspect the file contents properly you will find that they are exactly as you have written them. The problem is that you are telling the system to always write 10 characters regardless of the actual length of your text. When you open the file with Notepad it tries to figure out what the...
28 Nov 2015 by User 59241
The best way to convert binary string to number are the stoXX functions.http://www.cplusplus.com/reference/string/stoi/[^]So:#include #include int main(){ const std::string bitstr = "00001111"; int intval = std::stoi(bitstr, 0, 2); std::cout
18 Dec 2015 by Jochen Arndt
That happens because you are writing to an already existing file that has a larger size than the data you are writing. From the OpenWrite[^] description:Quote: If you overwrite a longer string (such as “This is a test of the OpenWrite method”) with a shorter string (such as “Second run”), the...
29 Jan 2016 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you may find it...
6 Mar 2016 by Sascha Lefèvre
Your question seems to indicate that you're not aware of the difference between a numeric value and its representation.Consider this:int number = 100; // representations:string numberAsBinary = Convert.ToString(number, 2); // =...
9 Mar 2016 by Jochen Arndt
The simplest solution would be checking the string (the characters) when the number is entered (as stated in the question):bool bResult = (*input != 0);int decPoint = 0;while (bResult && *input){ switch (*input) { case '.' : decPoint++; case '0' : case '1' :...
13 May 2016 by Dmitriy Gakh
I have no enough data about your solution and logic, but this code seems working without runtime errors (if it does not resolve your problem completely, it could be helpful to improve the situation and understand the code better):private void btnDelete_Click(object sender, EventArgs e) ...
19 May 2017 by OriginalGriff
Start by checking your save file with a hex editor, and making sure that what you think it contains is exactly what it does hold. Until you have made completely sure that the file that your readFile function is processing is complete, valid, and perfect, you can't even begin to debug the...
13 Nov 2017 by Jochen Arndt
You should have a device driver for the communication. This should provide functions to setup the interface and read and write data (usually with a pointer for the data and a size parameter). Quote: In the protocol there is a lot of Octets(octetos) which consists of 8 bytes that the protocol...
13 Nov 2017 by Patrice T
An octet is a byte: Octet (computing) - Wikipedia[^] Quote: ::= 05 Hexadecimal ::= 06 Hexadecimal ::= 15 Hexadecimal ::= 10 Hexadecimal Those are standard ASCII codes, this notation is used because those are non printable. Ascii Table - ASCII character codes and html, octal, hex and...
15 Nov 2017 by Patrice T
Quote: 10010 10011 10111 10110 1010 10111 10010 10011 11111 11110 10110 11100 11001 11110 10111 111 If you have: A2= 10010 B2= 10011 C2= 10111 D2= 10110 A3= 1010 B3= 10111 C3= 10010 D3= 10011 A4= 11111 B5= 11110 C5= 10110 D5= 11100 A6= 11001 B6= 11110 C6= 10111 D6= 111 Then =MAX(A2:D6) will do...
7 Mar 2018 by Richard MacCutchan
See Dyninst API | Putting the Performance in High Performance Computing[^]
10 May 2018 by Thomas Daniels
output is always just a one-letter string (because it's inside the loop), so reversing it just gives the same string. What you need to do, is reversing the whole string before printing it: def binary_converter(num): reverse = "" while num != 0: output = num % 2 # 0 or 1 ...
8 Jun 2018 by Patrice T
Quote: Does this code to insert to a tree not work for empty trees? First: read the code and particularly comments. // base case--we have reached an empty tree and need to insert our new // node here second: there is an easy way to know the answer, make a testing program that call the routine...
19 Mar 2020 by honey the codewitch
BinaryReader and BinaryWriter can be used to parse or write binary files more easily and in a portable manner
4 Dec 2020 by Member 13376231
An overview of a tricky binary collision example when there are multiple definitions of symbols in linked binaries
8 Apr 2021 by k5054
Try using xxd on linux to show your binary data as hex: [k5054@localhost tmp]$ cat hellow.cpp #include int main() { std::cout
9 Apr 2021 by Richard MacCutchan
You make the following call: File_*fp = open(dir, "rb+,ccs=UNICODE"); but that is not standard C. What is File_ and where is the code for open? It is also unclear why you are specifying a character encoding to read a binary file. Also the...
4 May 2021 by Rick York
Have you had a look at these ? procmon-parser · PyPI[^] GitHub - asquigglytwist/SeeBee: A PML Analyzer.[^] This might be helpful also : The Ultimate Guide to Procmon[^]
22 Jul 2021 by Greg Utas
If you're doing this on your own, you've chosen something that seems beyond your current skill set, so you should start with easier programming problems. If this is an assignment, it would hardly be the first one that you've been given. My guess...
17 Jan 2022 by OriginalGriff
All it does is mask and shift values: Look up the AND and shr operators and it's pretty obvious: Pascal - Bit Operators[^]
17 Jan 2022 by CPallini
public static byte [] getNibbles(UInt32 ui32) { const int Nibbles = 8; byte [] b = new byte[Nibbles]; for ( int n=0; n>= 4; } return b; }
6 Feb 2022 by OriginalGriff
Use the int(string, base) function to translate input from a base n to internal binary, add them, then convert back to the appropriate base to display: Python int() Function[^]
7 Feb 2022 by Richard MacCutchan
Once you have the integer values you can simply add them together to get the total. This holds true for any number. The key to your question is how to display them in the correct format. You need to use the base number to calculate each digit...
7 Feb 2022 by OriginalGriff
This is the same question you asked yesterday: Add two numbers given in base n format in python.[^] And since I told you exactly what to do then and you've ignored it, there is no point at all in asking it again. If I was you, I'd spend the...
17 Mar 2022 by Patrice T
Quote: I know this code is already very optimized as It takes O(log n) time. Indeed, but you take the 1 bit at the time approach. Your code runtime depend on position of leftmost bit set to 1. Bitwise approach can lead to much more optimized...
15 Jun 2022 by Richard MacCutchan
See convert object code to C source - Google Search[^] for some possibilities.
15 Jun 2022 by k5054
Probably the best you can do is to disassemble the object code. Not that that's going to help you much as this will return Assembler codes, and not C language (or any other High Level Language). Depending on the optimization level, there may be...
15 Jun 2022 by KarstenK
You better invest your time in some Learn C tutorial instead of try to cheat. This "reverse engineering" isnt so easy because it may not work or the resulting code is bizarre. Functions may have names like "func1" and so on. So you may end in a...
23 May 2011 by Stuart Nathan
You can still use VB6 code such as fileget and fileput in VB.NET (Option Explicit Off)or if you are reading fixed length files then some code to help you on your way.Public Class RandomFile Private fs As FileStream, sr As BinaryReader, sw As BinaryWriter Private FieldString(),...
23 May 2011 by Thomas Krojer
this can be done easy with reading the file in a byte array.
20 Jul 2011 by helldevil1912
I want to get information of ASF file as bitrate, metadata, language...I have read ASF Specification and know a ASF file has parts : Header Object, Data Object, Index Object. At frist, I think ASF file's binary file and i try to solve by CLASS and FUNCTION in C# as : FileStream, BinaryReader...
20 Jul 2011 by Suresh Suthar
Hi,This will not work at all.I think these link will...
5 Sep 2011 by bandroid
HiI am developing a web application. In this application a user can upload and download a file .pdf and stored in Sql Server as binary.I show the list of files in a gridview. When user clicks on a download button in gridview it can be downloaded the file on client side.Can some one help...
5 Sep 2011 by OriginalGriff
I do it like this: I have a table in my page, to which I add all the relevant file names from my DB.An ASPX control then handles the download for me, based on the row index from the DB.Page Load event handler:Dictionary downloads = GetDownloadList();StringBuilder sb = new...
5 Sep 2011 by Sudhir Kumar Srivastava lko
"Hope this link will help u" http://imar.spaanjaars.com/414/storing-uploaded-files-in-a-database-or-in-the-file-system-with-aspnet-20[^]
21 Nov 2011 by NguyenVanDuc
I have an aspx( contain binary of one mp3 file), and i want to play this file using that aspx page. Please help me!
21 Nov 2011 by Abhinav S
Try outMP3 Player Server Control[^]http://ultidevwebbasedmp3pl.codeplex.com/[^]http://www.asp.net/community/control-gallery/Item.aspx?i=2015[^]http://www.aspnetmedia.com/[^]http://www.wonderhowto.com/how-to-play-mp3s-asp-net-web-applications-259021/[^]
3 Dec 2011 by Captain Price
I've created a text file Encoded in ASCII. It Contains the Following Text;abcd123Binary value of the above text ;01100001 01100010 01100011 01100100 0110001 0110010 0110011 How Can I do this (getting binary value of a file to a text box) in C# ?
3 Dec 2011 by OriginalGriff
Reading text is easy: MSDN[^]byte[] data = File.ReadAllBytes(path);Converting to binary is easy: MSDN[^]string s = Convert.ToString(myByte, 2);Put them together with a foreach loop and a StringBuilder and you have a program...But, since this is your homework, I'm leaving the actual...
3 Dec 2011 by RaviRanjanKr
You can also to it by using LINQvar str = "abcd123"; foreach (string letter in str.Select(c => Convert.ToString(c, 2))) { Console.WriteLine(letter); } Console.ReadLine();For more reference :- How do you convert a string to...