• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Confusion with Binary, Byte representations

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)


 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic