Little endian function?

Started by
5 comments, last by Burty 20 years, 1 month ago
How would you write a function will return true for systems which use a little-endian byte ordering, and false for systems which use a big-endian byte ordering. I am doing a test but not doing great so any help would be appreciated. Thanks B
Advertisement
This is not the appropriate place to ask for homework/exam help.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Why do you want to do this? If you program whatever it is you''re doing properly, it shouldn''t matter.
Anyway, it should be fairly trivial. A byte can contain up to 255, so anything over 255 will go into 2 bytes. So, 256 will have 1 in the high byte, and 0 in the low byte. Then you find out what byte is the high byte, and you can get the answer to your question from that.
All you need to do is think about when it would matter which endian format you were using. Once you know that a check for it should be easy.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
So you are asking us to help you cheat on your test?

Don''t you realize that although you won''t look as good because you can''t answer the question, you will look very bad when they discover that you cheated on the test?

In a phone interview recently, a candidate was asked about dot products. He said he was very familiar with that, but needed a few seconds to remember the details. In the few seconds that it took him to "remember", lots of typing could be heard. After a few seconds of typing, he responded with an answer that was obviously quoted from a reference that he just read. The interview ended quickly.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
quote:
So you are asking us to help you cheat on your test?


There is no way you can be sure of that.
quote:Original post by Anonymous Poster
quote:
So you are asking us to help you cheat on your test?


There is no way you can be sure of that.


Which might be the reason for the question mark at the end of his _question_ ?

This topic is closed to new replies.

Advertisement