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

Reading a JPEG's Binary Code

Hello! I am new to the whole programming world (enjoying it). I wanted to work with jpeg files. I read in a jpeg file using the open method with "rb" which it all works fine. Then I wrote all its binary code into a text file to analyze.

The text file looks a lot like hex-decimal. The thing I do not understand is, how come there are characters like "?" and "(" mixed in the code.? I have also seen 00Z mixed in. Shouldn't it all be from 0 to F only?

I noticed these symbols do not appear if I open the file with HxD. In fact, some of the Hex code is different.
Oct 22 '14 #1
3 2574
When I open with HxD, it has a particular Hex number as 00 5A 00 5A. In python, where that piece of code should be; I get 00z00z. I am confused by that.
Oct 22 '14 #2
Rabbit
12,516 Expert Mod 8TB
Binary does not equal hex. You have to convert the binary to hex representation before writing it to the file.

In binary, the value could be something like 01011010. Which in decimal is 90, in hex it's 5A. All those values: 01011010, 90, and 5A are merely different visual representations of the underlying binary data. How the binary data is represented is up to the program. For example, the text editor can read in the binary 01011010 and convert that into it's corresponding ASCII value of Z and display that to you. Whereas if you open the same file in an image editor, it will take the same value and convert it to a color.

If you want to take the binary data and change the way a text editor displays the data, then you need to make that conversion. If all you do is read in binary data and write out the same binary data, all you're doing is making a copy of the file.
Oct 22 '14 #3
"For example, the text editor can read in the binary 01011010 and convert that into it's corresponding ASCII value of Z"

You hit the nail there. Thanks. I'll keep playing with this.
Oct 22 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jón Sveinsson | last post by:
Hello everyone I have been able to read data from binary files to filestrean, the data in the files are structured, what I'm trying to do is to loop through the binary files and add data to my...
6
by: Eddie | last post by:
Hi, Is it possible to make a program in VB.net that will convert letters, numbers etc to Binary Code? I have the tables here that show me exactly what each character works out to, but I was...
1
by: jen4022599 | last post by:
Is there a function or a project i can call to convert my numbers into binary code? thanks
1
by: cs2801 | last post by:
Im trying to do this for work. I am to design a binary code for encoding words. They are both upper and lower case, basic punctuation,16 different font styles, bold, itilicied, underlined or regular,...
19
by: citronelu | last post by:
Is it possible to execute a binary string stored within a python script as executable code ? The script is run under Windows, and the binary code (a full executable file) is stored in a variable...
31
by: tophandasa | last post by:
Hi all, I'm having a trouble reading a binary file as float values.I have to read the data in binary mode, then read every four bytes into a float variable. I have done my search, but i found out...
1
by: getgroup | last post by:
Can python maky a binary code for exemple .hex for microcontrolor. tks
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
4
by: lipeacorsi | last post by:
Hi, I've got a program that decrypts a fille and i don't want to write the decrypted binary code to an exe so that i can run it. Is there anyway that i can load the inexisting file just having it's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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
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.