Click here to Skip to main content
13,191,400 members (76,962 online)
Rate this:
Please Sign up or sign in to vote.
See more:
As anyone knows that computer working on binary (0s and 1s).
Every file/data have its binary source.
I want to Read/Access and edit binary of data/files like(.MP4 , .MP3, .ISO etc) in visual basic.
How can is do that?
Posted 21-Jan-13 5:56am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:
valery possoz 21-Jan-13 16:42pm
For what ever reasons I think he want 0s and 1s... What about adding Dim bits As New BitArray(data)?
5 anyway :)
Alamgirable 22-Jan-13 7:57am
Can you plz tell me how to call its binary data.
For example:After opening file using your above given method i want to make first binary value to equal 11 or 00.
Like this:
for example the first binary value of ("D:\Temp\MyVideo.mp4")is 1 or 0 i want to make it equal 11 or 00.
OriginalGriff 22-Jan-13 8:08am
Soory - pleas etry to explain that a little better, perhaps with an example showing byte values.
If you want to replace a byte &H01 with a byte &H11 or &H03 that is easy - but your comment implies you might be trying to insert a single bit in the entire file, which is a lot harder! (And will wreck the file as far as it still being a valid video is concerned)
Alamgirable 22-Jan-13 9:12am
Actually i want to edit the binary file and then compress it using algorithm.
Sorry for bad english.
OriginalGriff 22-Jan-13 9:21am
You probably don't want to treat it as binary data - that will likely be far too slow - bytes are the "natural" size of most algorithmic compression as they are far, far easier to work with (or you might want to work with the hardware's true natural unit (32 or 64 bits) for speed.

Be aware that MP4 and MP3 and so forth are already compressed data formats, and you are unlikely to gain much in compression (unless you have a new, wonder algorithm, in which case sell it to someone big for serious amounts of money!)
Alamgirable 22-Jan-13 9:26am
OK,Above you said that "If you want to replace a byte &H01 with a byte &H11 or &H03 that is easy" then tell me how can i replace byte.
Plzzzzz show me it with coding example.
OriginalGriff 22-Jan-13 9:31am
Look at the code in my original answer - it replaces the value in the first byte (byte zero) with the hexadecimal value FF (or decimal 255)
Alamgirable 22-Jan-13 9:35am
How can i change (byte zero) with the binary (Mean FF = 1 OR 0)
OriginalGriff 22-Jan-13 9:46am
You are joking, right?
data(0) = 0
Data(0) = 1
Alamgirable 22-Jan-13 11:12am
I,m not joking.Actually i'm 15 year old boy and i'm new in computer programming.
OriginalGriff 22-Jan-13 11:51am
Even if you're 15, you are expected to think and apply what you are shown to your own problem.
It's not exactly a massive stretch from my original code to the revised version, is it? :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171017.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100