### Author Topic: Quick question: bytes  (Read 3621 times)

0 Members and 1 Guest are viewing this topic.

#### osnap

• Jr. Member
• Posts: 24
• Helpful? 0
##### Quick question: bytes
« on: August 13, 2007, 10:42:01 PM »
I've been looking at charts and stuff latley that list the bits in a byte, and everything seems to be backwards.

Just to make sure, if i have an 8 bit byte, the 0th bit starts on the left right?

value: 01110010
num:  01234567

#### HDL_CinC_Dragon

• Supreme Robot
• Posts: 1,261
• Helpful? 5
##### Re: Quick question: bytes
« Reply #1 on: August 13, 2007, 10:54:59 PM »
wrong, it goes from right to left.

0000001 in binary = 1
0000010 in binary = 2
0000011 in binary = 3
0000100 in binary = 4
0000101 in binary = 5
0000111 in binary = 6
and so forth

its goes like this
0 0 0 0 0 0 0 0
256 128 64 32 16  8  4  2

so 10000000 would equal 256 in decimal
and 10000001 would equal 257 in decimal

see how that goes?

Hope this helped

-Edit-
8 bits - 1 byte
1024 bytes = 1 kilobyte
1024 kilobytes = 1 megabyte
1024 megabytes = 1 gigabyte
1024 gigabytes = 1 terrabyte
1024 terrabytes = god
« Last Edit: August 13, 2007, 10:56:32 PM by HDL_CinC_Dragon »
United States Marine Corps
Infantry
Returns to society: 2014JAN11

#### DomoArigato

• Full Member
• Posts: 54
• Helpful? 1
##### Re: Quick question: bytes
« Reply #2 on: August 14, 2007, 06:46:06 PM »
If the number is a signed integer, it will look different too.  It will usually be in 2's compliment form. http://en.wikipedia.org/wiki/Two's_complement

#### Admin

• Administrator
• Supreme Robot
• Posts: 11,702
• Helpful? 173
##### Re: Quick question: bytes
« Reply #3 on: August 14, 2007, 08:51:59 PM »
Another example, the registers on a microcontroller:

pin A0:
00000001

pin A1:
00000010

pin A2:
00000100

etc.

#### osnap

• Jr. Member
• Posts: 24
• Helpful? 0
##### Re: Quick question: bytes
« Reply #4 on: August 14, 2007, 11:19:21 PM »
oh crap i just screwed up my fuse bits then

LOL

well at least i got that cleared,

thanks for the replies!

#### cybcode

• Jr. Member
• Posts: 18
• Helpful? 0
##### Re: Quick question: bytes
« Reply #5 on: August 19, 2007, 12:11:01 PM »
I think maybe a small mistake was made in a previous post in this thread.

The decimal values for the bits in a byte start with 1, not 2:
128 64 32 16 8 4 2 1

so
0000 0000 = 0 in decimal
0000 0001 = 1
0000 0010 = 2
0000 0011 = 3
...
0111 1111 = 127
1000 0000 = 128
1000 0001 = 129
...
1111 1111 = 255

That's as high as a byte can go.
And all that is correct assuming the byte is interpreted as unsigned, which means it can go from 0 to 255.

If the byte is signed, it can go from -128 to 127, like this:
0000 0000 = 0
0000 0001 = 1
0000 0010 = 2
0000 0011 = 3
...
0111 1111 = 127
1000 0000 = -128
1000 0001 = -127
1000 0010 = -126
1000 0011 = -125
...
1111 1111 = -1

It's easy to remember it generally like this:
the least significant (=low=first=right) 7 bits are always interpreted normally: 64 32 16 8 4 2 1
in unsigned mode, the most significant (=highest=last=left) bit is interpreted as +128
in signed mode, it's interpreted as -128
all you have to do is write the values of all bits on top of them, and then add up the values wherever there's a 1.

for example:
to find the value of 10110100 in signed mode, you do:
-128*1 + 64*0 + 32*1 + 16*1 + 8*0 + 4*1 + 2*0 + 1*0 = -76
if that was an unsigned byte, its value would be 180.

This way of interpreting signed/unsigned integer values agrees with the 2's compliment concept. What I mean is - these aren't two different forms, they're the same. (I'm just making sure I'm not confusing anyone.)
« Last Edit: August 19, 2007, 12:19:08 PM by cybcode »

Get Your Ad Here

data_list