2 Replies - 3246 Views - Last Post: 23 July 2012 - 10:09 PM Rate Topic: -----

#1 croog24  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 10

0xa Value Clarrification For Hex Conversion

Posted 23 July 2012 - 11:47 AM

Hello everyone!

For practice, I'm making a hex reader. In this scenario, I read a text file and convert the text to hex. Simple enough. However at the end of it is the value 0xa. Is this basically an EOF marker? I've tried the same with just a string and it doesn't appear.

Thank you!

f = file('test', 'r')
content = f.read()
for x in content:
	test = bytearray(content)
for i in test:
	print hex(i)



test file content:
Hello World!

Is This A Good Question/Topic? 0
  • +

Replies To: 0xa Value Clarrification For Hex Conversion

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: 0xa Value Clarrification For Hex Conversion

Posted 23 July 2012 - 12:05 PM

0x0A is equal to decimal ten. This is equal to the ASCII code for LF (Line Feed), which is a newline on many systems.

Answer found using google.

This post has been edited by atraub: 23 July 2012 - 12:07 PM

Was This Post Helpful? 0
  • +
  • -

#3 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2088
  • View blog
  • Posts: 3,176
  • Joined: 21-June 11

Re: 0xa Value Clarrification For Hex Conversion

Posted 23 July 2012 - 10:09 PM

View Postatraub, on 23 July 2012 - 09:05 PM, said:

LF (Line Feed), which is a newline on many systems.


As long as you open the file in text mode, it's a newline on all systems (which is to say: no matter what the system's native newline character is, Python will translate it to a line feed when reading the file).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1