Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Confusion with Binary, Byte representations  RSS feed

 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I got this code snippet from this Binary File Processing resource link.



I am just confused with the "0x00" and "0xFF" stuffs. Why should we assign the char variables to hexadecimal representations?
Hope you can help me. Thanks!

Here's the complete code by the way (writing/reading to/from a binary file)


 
Henry Wong
author
Sheriff
Posts: 22836
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just confused with the "0x00" and "0xFF" stuffs. Why should we assign the char variables to hexadecimal representations?


The representation is for the developer. The compiler doesn't care what representation you use. In general, hexidecimal is preferred for binary data because it can be easily envision -- two digits with each digit representing 4 bits easily.

However, if you feel more comfortable with decimal, feel free to use that instead...



Henry
 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see.. Thanks a lot!
Just a note, Binary Editors are also helpful. Now I get that they represent binary data positions in hex.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!