negative hex

difference=%d\\n", first, second, result);

difference=16733234

difference=-2147483392

Try some leading minus signs.

easier in

I'm not an avid programmer. I hate to program, so I get it over as soon as possible. I'd rather design hardware.

But the language doesn't matter; I just need to settle on a notation that my customers can use. So, it's...

Absorb the characters after the "x" as nibbles packed into a 32-bit register. If there had been a leading - sign, negate that register after all the "0..F" characters are crunched.

of

The whole program is around 6 kloc, not the parser. The command parser proper is about 75 lines of executable code, and the "get an integer from the command string" subroutine is another 35 or so, now that I've added the signed "0x" hex option.

I'm up to about 260 distinct serial commands so far. The parser is looking pretty good, fast and nicely table-driven, so we'll use it in a lot of other products. We did a couple of products with proper SCPI syntax analyzers, and they were bags-o-worms. SCPI is insane.

John

Reply to
John Larkin
Loading thread data ...

FFFF is either -1 or 65535 according to whether it is a signed or unsigned quantity

To say -FFFF is like saying "I'm going to subtract -1". Generally if I do this it is with a sense of guilt that I can't be bothered to negate it.

Reply to
richard

The wiki entry on "hexidecimal" has many, many more.

John

Reply to
John Larkin

On a sunny day (Sun, 29 Jun 2008 11:39:56 -0700) it happened John Larkin wrote in :

difference=%d\\n", first, second, result);

Actually I did, and it is really interesting: grml: ~ # ./test_ Enter first number

0x255 Enter second number

-0x255 The first number is 597, the second number=-597, and the difference=1194

The answer is correct! Had to think about it a few moments though :-)

easier in

OK, well I actually like to program (not all the time, so maybe it was projection). Once had a boss who was into x86 asm big time, he would sit down next to me, and take over (he was the million $ man), and he would do it in the evening at home too.

That is why keeping to something like '-i' in C will allow your customers to use for example both hex and decimal, with + and -, mixed if need be :-)

of

OK

Yes, it can be vary compact in asm. I have used jumptables from serial in myself at times.

That gave me only 255 different commands though :-)

Reply to
Jan Panteltje

Although Wikipedia references the misspelling to the correct page, you'd probably get more googlehits if you spelled it correctly. It's hex*a*decimal.

There are only three common words in English that start with hexi:

hexing hexine hexitol

There are about 120 common words that start with hexa.

Best regards, Spehro Pefhany

--
"it\'s the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

After 9, they usually hang trying to figure out what to do with the carry bit.

If they're clever, they will take off at least one shoe and continue counting.

Those that live in a hexadecimal world, will count: 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 Those that do octal will count: 0 1 2 3 4 5 6 8 10

Programmers that are into algorithms will never make it past the initial 0 spending hours trying to find the most efficient way to count sequentially. The usual result is 0 10 skipping everything in between.

The compulsive programmer will write a short program to remind them how to count sequentially. This usually takes a dozen tries due to compiler bugs, logic errors, forgetting to initialize variables, bad choice of data type, misformatted output, etc. The correct sequence will eventually be produced, but only after hours of debugging.

The computer scientists and architects will ask if I want the results in some particular radix, big endian or little endian, byte swapped, or encrypted.

Unfortunately, in reality-land, the counting trick doesn't work very well. I've tried it on a few programmers. All but one started counting with "1", exactly like the rest of the human race. The one programmer that started with "0" knew about the joke.

--
Jeff Liebermann     jeffl@cruzio.com
150 Felker St #D    http://www.LearnByDestroying.com
Santa Cruz CA 95060 http://802.11junk.com
Skype: JeffLiebermann     AE6KS    831-336-2558
Reply to
Jeff Liebermann

What happen to 7 ?

Shouldn't it be: 0 1 2 3 4 5 6 7, then 10 2^3 = 8; A total of 8 combinations. etc.. ?

formatting link
"

Reply to
Jamie

If you'd like to correct the spelling, syntax, punctuation, and math of my comments, feel free to post your impeccably edited follow-ups.

John

Reply to
John Larkin

Typo error. I hit 8 instead of 7.

Grumble. My spelling chequer didn't catch the sequence error.

Incidentally, the first computah I used was an IBM 1620. Variable length word with BCD instructions and data. It's been downhill ever since.

--
Jeff Liebermann     jeffl@cruzio.com
150 Felker St #D    http://www.LearnByDestroying.com
Santa Cruz CA 95060 http://802.11junk.com
Skype: JeffLiebermann     AE6KS    831-336-2558
Reply to
Jeff Liebermann

that makes trivial to compute the area of the circle with radius Pi,

A = 1 * 1 * 1 = 1

Jure Z.

Reply to
Jure Newsgroups

In that case, you'd use a decimal radix.

Tom

Reply to
Tom2000

I performed an experiment for you, and I received sarcasm for my troubles.

I wrote you a lucid explanation, and what do I get? More sarcasm.

I've had enough.

Hit the books. And don't let your boss see your code.

Reply to
Tom2000

Too often in USENET, a senior engineer will pose a question to which the answer is trivial and receive a condescending response. The responder does not know that the answer is condescending because s/he has been responding that way to posters for years (perhaps), assuming that, if the poster is asking a question, then he must be generally ignorant within the context of the questions.

I think that might have happened in this case.

See. That's just it: John Larkin is not confused in the least about this stuff. Nor is he in state of ignorance from which he needs to be relieved.

His question was more like: "Does anyone eat bananas around here?"

I think it is a good habit to either evaluate where the poster is at, or presume that the poster is not in state of ignorance and let him/ her guide you to what s/he needs.

One thing to think about, in this particular case, is that John Larkin could probably design, or at least explain in detail, the entire food chain from raw silicon to a full 32-bit state machine a device for processing signed/unsigned numbers.

-Le Chaud Lapin-

Reply to
Le Chaud Lapin

Experiment?

I didn't want an explanation, I didn't want another lecture, I wanted to know if there was an accepted convention for expressing a negative hex constant. -0xDABBE seems like the concensus, with the resulting number actually being negative.

And it wasn't so much lucid as wrong. But thanks for trying.

Matter of opinion. Usenet is not for the tetchy.

Tragic.

What books?

I am the boss.

John

Reply to
John Larkin

They may not _make_ value judgments, but most _offer_ them in the form of their flag bits.

If one of the offered value judgments fits with the meaning you wanted the bits to have, then you can have it do something based on the relevant flag bit...

Reply to
cs_posting

It has been interesting. Asking about a notation convention,

Roughly a third of responses lectured me on basic 2's complement math, the majority of them arguably wrong.

Roughly half said "that's impossible" or "don't do that" or "your C compiler won't let you do that" or "your boss should chase you with a baseball bat." I don't even have a C compiler.

Of those who agreed that it's not technically impossible to type the characters "-0xFEEE", there was roughly an even split of what the sign of the evaluated number might be.

Now wonder planes fall out of the sky.

formatting link

John

Reply to
John Larkin

For an ongoing, daily account of such things, see:

formatting link

--
Regards,

John Popelish
Reply to
John Popelish
[snip]

I'm always amused that, during each new model year introduction for automobiles, the number of dead new GM and Mercedes vehicles along the roadside is astronomical.

Must be all those "updates" ;-)

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC\'s and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
|                                                                |
|        Vote Barack... Help Make America an Obama-nation        |
|                                                                |
|  Due to excessive spam, googlegroups, UAR & AIOE are blocked!  |
Reply to
Jim Thompson

Not strictly necessary, but a wise precaution. People make typing mistakes that result in similar errors with signed/unsigned quantities.

I expect word here is specified as a signed number whereas hexadecimal constants are implicitly specified as unsigned. The coercion to signed has generated a range check for a value with the top bit already set.

I wouldn't read too much into what a particular program happens to do.

However, you should give some consideration to the awkward boundary special case.

.WORD -0x8000 .LONG -0x80000000

There is a small problem here that a signed 16 bit word -2^15

Reply to
Martin Brown

LOL. :)

-Le Chaud Lapin-

Reply to
Le Chaud Lapin

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.