User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » hex and binary operations? Page [1]  
Chop
All American
6271 Posts
user info
edit post

is it true that the leftmost bit always indicates the sign of the integer? i understand the concept of the two's compliment and how to find it. i'm just not sure when you're supposed to do it. for example, how do you know if the hex number FFC9 equals 65481 or -55? if the leftmost bit indicates the sign, is it safe to assume any hex number that starts anything between 8 and F is a negative integer?

also, generally speaking, how are decimal places determined? if i have a 16 bit word with 8 bit precision, does that i mean i have 8 bits of whole number and 8 bits of decimal? (sorry, i'm not clear on the terminolgy/syntax)

i'm a mechanical engineer, so this is somewhat new to me, and i've pretty much had to teach myself this stuff over the course of the day today. this is for a microprocessor controller i have to test/validate at work.

12/5/2006 12:09:14 AM

ruffler
Veteran
108 Posts
user info
edit post

A number isn't signed or unsigned by itself. It depends on how you want to interpret it.

12/5/2006 12:26:05 AM

moron
All American
34142 Posts
user info
edit post

Take ECE 212. It's a pretty easy class (esp. if you get Conte) and you'll be much less confused for it.

12/5/2006 1:59:16 AM

hydro290
All American
1703 Posts
user info
edit post

Think of it in bits. FF is just 1111 1111.

If you want to interperet this as unsigned, the number is 255.

1*2^7 + 1*2^6 + 1*2^5 + 1*2^4 + 1*2^3 + 1*2^2 + 1*2^1 + 1*2^0 = 255.

However 1111 1111 can also be interpereted as -1.

To determine the 2's complement of a negative integer, determine the 1's complement (by flipping the bits of the positive integer) and add 1.

The number 1 is 0000 0001. Flipping the bits makes it 1111 1110. Adding 1 makes it 1111 1111.

12/5/2006 10:42:30 AM

Blind Hate
Suspended
1878 Posts
user info
edit post

Quote :
"A number isn't signed or unsigned by itself. It depends on how you want to interpret it."

12/5/2006 10:48:50 AM

SMokE
Veteran
227 Posts
user info
edit post

I think the 2's complement part of your question has been pretty well answered so far, but just to recap...

If you're interpreting a bitfield as 2's complement, there are basically 2 rules to keep in mind:
1) If the highest order bit is set, the number is negative. To interpret a negative 2's complement number, negate it. That brings us to the next rule...
2) To negate a 2's complement number (positive->negative or negative->positive, it doesn't matter), invert all of the bits, then add 1.

Along with these rules, a couple things to keep in mind:
-If the number takes up more than 1 byte, watch out for endianness (byte order)
-The range of a two's complement number is always one step more in the negative direction. For example, a single byte interpreted as two's complement can represent any number in the range -128 through 127.

Your question about precision really depends on the context. In general, precision refers to the number of bits used to represent some value. With a microcontroller, this usually comes into play with an analog-to-digital converter (ADC). An 8-bit precision ADC would only actually use 8 bits, regardless of the size of the register or memory location it is writing to. For example, an ADC with 8-bit precision that could measure values from 0mV through 510mV, would only be giving you values in 2 mV increments because it only uses whole numbers from 0 through 255.

While I'm on the subject of precision, another cautionary note: don't confuse precision with accuracy! You've probably already heard this in the context of mechanical engineering, and it still applies in electrical.

12/5/2006 1:00:13 PM

Chop
All American
6271 Posts
user info
edit post

thanks for the replies. i talked with the guy who actually did the design/developed the controller today and he echoed pretty much the same thing . . . math, crazy stuff.


Quote :
"Take ECE 212. It's a pretty easy class (esp. if you get Conte) and you'll be much less confused for it."

unfortunately this isn't an option as i graduated 6 years ago.

12/5/2006 11:02:38 PM

 Message Boards » Tech Talk » hex and binary operations? Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.