Go Down

Topic: byte description in http://arduino.cc/en/Reference/Byte (Read 8557 times) previous topic - next topic

Pat-The-Pirate

Hi.

I wonder if it would be clearer to define the byte as having 8 bits? In the text it says

Example

    byte b = B10010;  // "B" is the binary formatter (B10010 = 18 decimal)


I'd have thought we should see

byte b = B00010010; // "B" is the binary formatter (B00010010 = 18 decimal)

Otherwise there is a possibility that people might forget about the leading zeros.

Peter_n

I agree, all 8 bits is better.
However, it's impossible to get those reference pages changed. There are errors on some pages that stay for years.

PaulS

Quote
Otherwise there is a possibility that people might forget about the leading zeros.

The leading zeros don't mean squat. What if people forget about them? They don't mean anything, so there is no harm in forgetting them.
The art of getting good answers lies in asking good questions.

Delta_G

Except when you are teaching someone what a byte is and leave them with the impression that it only has 5 bits.  Remember Paul, this site is for beginners.  I think you'd be much happier on a board for full fledged programmers, that way you don't get so confused between stupid and beginner so often. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

MarkT

I'd strongly suggest both versions are as bad as each other and it should be:
Code: [Select]

byte b = 0b00010010; // "0b" is the binary formatter (10010 binary = 18 decimal)
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Peter_n

http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html

Pat-The-Pirate

Hi Folks,

Thanks for the help. I'm a TOTAL newbie & using Aitken & Jones "C in 21 days" 870+ pages book to try and understand how it all hangs together in Arduino land.

I suspect MarkT's reply is on the mark. I thought of leading (or trailing) memory locations when looking at the bitwise instructions.

I'm now awaiting the post for my first Uno to arrive . . .

Pat

AWOL

Leading zeroes have their own particular pitfall in C - without an explicit prefix like 0x or 0b, they make the constant an octal number.

Code: [Select]
Serial.print ln (010); will display the single digit 8.

MarkT

"Pitfall" is putting it mildly, what were they thinking?  Compare
Code: [Select]

  int i = 8 ; // 8
  int j = 08 ; // syntax error!
  int k = 08. ;  // 8
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

AWOL


Peter_n

I changed my signature/quote into this: Says one Arduino board to the other: 0100100001100101011011000110110001101111001000000101011101101111011100100110110001100100 !

As you can see, it is totally clear what it says. It is a data bit stream, without any overhead. The leading zero is essential. Without it, you all would wonder what it could mean ;)

bobcousins

There is always a conundrum, do you teach people something simple but misleading, or something correct but confusing? There is no way round the fact that C/C++ are complicated things.

I think it is a bad habit to teach people to put leading zeros in numeric literals, especially in C/C++. If they can't read and understand the definition that says "A byte stores an 8-bit unsigned number" then they have bigger problems!

Specifying a binary prefix or padding to 8 bits does not make the value a byte, the type will be int. It would be better to teach people how numbers work, why leading zeros are not significant and perhaps how bits are stored if necessary.
Please ask questions in the forum so everyone can benefit. PM me for paid work.

PaulS

Quote
The leading zero is essential. Without it, you all would wonder what it could mean

You might think that it is essential, but, by itself it is not enough. There is nothing in the presence, or absence of that 0 that makes the rest of the characters have meaning.
The art of getting good answers lies in asking good questions.

Peter_n

You didn't try to read the bitstream ?
It is a bitstream without start or stop bit. Missing the first zero, would result in rubbish.

bobcousins


You didn't try to read the bitstream ?
It is a bitstream without start or stop bit. Missing the first zero, would result in rubbish.


So is there parity, CRC, FEC? What is the word size? Is it fixed or variable? Is it compressed? What algorithm? Without further information, your bitstream may as well be rubbish.

Your contrived example proves nothing, and is not relevant to the topic.

Binary is for computers, not people, so if you wish to communicate with people, putting binary data in a signature is daft, IMO.
Please ask questions in the forum so everyone can benefit. PM me for paid work.

Go Up