Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Codeproject,

Assuming I have two bytes:
C#
byte One = 0;
byte Two = 1;

If I save these, will One be less than two since the byte value itself is less? I mean, everything is written in bitcode. But are all the bits of the bytes the same length such as:
C#
bit One = 010101;
bit Two = 011101;

Or would it be more like this:
C#
bit One = 010;
bit Two = 010011;

I'm not sure if I'm able to ask this in an understandable way but, do bytes have different bitlengths?
Posted
Updated 21-May-13 9:31am
v3
Comments
Sergey Alexandrovich Kryukov 21-May-13 15:12pm    
"ID of a byte" means only one thing: gibberish:
http://en.wikipedia.org/wiki/Gibberish

—SA

A value typed as byte will always use at least 8 bits: Integral Types Table (C# Reference)[^].

Regards,

— Manfred
 
Share this answer
 
v2
Comments
Yuriy Loginov 21-May-13 14:18pm    
I think it will always use exactly 8 bits, no?
Manfred Rudolf Bihy 21-May-13 17:36pm    
Not always, since a compiler can always choose the optimal representation. Sometimes using word or double word aligned bytes can cause a significant performance gain. It all depends on how the byte is supposed to be used. There is an attribute called SequentialLayout that also plays a role in how a compiler may be constrained in optimizing an internal representation of a value.
You are confusing bytes with strings representing bytes. This is very frustrating. The only one thing can come: learn some computing from the very beginner. Answering your particular question won't help you. Instead, you should understand how data is represented in principle, how variables and types work, what .NET does, what the language and a compiler do. Right not, you don't have a clue.

—SA
 
Share this answer
 
Any value will be padded with 0's (for a positive or unsigned number) or 1's (for a negative signed number) to fit the size of the value it's in (8 bits for bytes, 16 for short, etc.).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900