Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Convert native character string to ASCII array of integers

Reply
Thread Tools

Convert native character string to ASCII array of integers

 
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      03-29-2008
CBFalconer:

> > Also, it is assumed that every char is valid ASCII.

>
> Which is a silly assumption. *However, you are still failing to
> initialize pc and pos.



Firstly, there's no such thing as a silly assumption in programming.
If I say the string has to be all valid ASCII characters, then the
string has to be all valid ASCII characters. It's not rocket science.

Also, why are you trying to critique my code when you haven't even
read it properly? Firstly you critisize the code for not doing three
specific things -- three specific things that it wasn't intended to
do, and now you can't get your head around the fact that pc and pos
are parameters to the original function that I wrote. You'd probably
be wise to view the original post before you critique the code further.
 
Reply With Quote
 
 
 
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      03-29-2008
On Mar 29, 3:43*am, Peter Nilsson <(E-Mail Removed)> wrote:
> Tomás Ó hÉilidhe <(E-Mail Removed)> wrote:
>
> > * * * * case '$': *pos = 0x24u; break;
> > * * * * case '@': *pos = 0x40u; break;

>
> $ and @ are not guaranteed members of implementation
> source or execution character sets.



Thanks!
 
Reply With Quote
 
 
 
 
Philip Potter
Guest
Posts: n/a
 
      03-29-2008
Tomás Ó hÉilidhe wrote:
> CBFalconer:
>
>>> Also, it is assumed that every char is valid ASCII.

>> Which is a silly assumption. However, you are still failing to
>> initialize pc and pos.

>
>
> Firstly, there's no such thing as a silly assumption in programming.
> If I say the string has to be all valid ASCII characters, then the
> string has to be all valid ASCII characters. It's not rocket science.


There *is* such a thing; a silly assumption is a tacit assumption. As
long as it is well documented, it is fine.

> Also, why are you trying to critique my code when you haven't even
> read it properly? Firstly you critisize the code for not doing three
> specific things -- three specific things that it wasn't intended to
> do, and now you can't get your head around the fact that pc and pos
> are parameters to the original function that I wrote. You'd probably
> be wise to view the original post before you critique the code further.


It is characteristic of Chuck's posts that he doesn't read the thread
before butting in. I find it much easier just to killfile him.
 
Reply With Quote
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      03-29-2008
On Mar 29, 11:25*am, Philip Potter <(E-Mail Removed)> wrote:

> There *is* such a thing; a silly assumption is a tacit assumption.
> As long as it is well documented, it is fine.



I've accepted "silly assumptions" with open arms ever since I finished
my Ordinary Degree project this year. It was an embedded systems
project which involved four different chips communicating with each
other. If any of the chips made an error, there could be a short
circuit from 5 V to 0 V which would fry the chips, the power
transistors, and also the voltage regulator. Given that the
micrcontroller ran at 8 MHz, and also that it performed one
instruction per clock cycle, it had 8 million chances to screw up
every second. I was advised to add extra resistors to allows for these
errors but I declined the suggestion. Instead I relied on everything
working perfectly. The finished product has been plugged in constantly
overnight for the last two nights and hasn't had a hiccup. When
programming, I assume that the computer will work perfectly every
time. Of course tho, if you're worried about human error you can
always use assert's.
 
Reply With Quote
 
Morris Dovey
Guest
Posts: n/a
 
      03-29-2008
Tomás Ó hÉilidhe wrote:

> If any of the chips made an error, there could be a short
> circuit from 5 V to 0 V which would fry the chips, the power
> transistors, and also the voltage regulator.


> The finished product has been plugged in constantly
> overnight for the last two nights and hasn't had a hiccup.


I'm reminded of an early computer cash register system in a gas
(petrol) station that worked without problem for over a year and
a half - until a police car pulled in for refueling. Just as the
car arrived, the dispatcher called on the radio and when the
policeman responded, his transmitted signal killed the pump
controller which, in turn, killed the cash register.

It might not be a bad idea to add those inexpensive
current-limiting resistors...



--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      03-29-2008
Philip Potter <(E-Mail Removed)> writes:

> Tomás Ó hÉilidhe wrote:
>> CBFalconer:
>>
>>>> Also, it is assumed that every char is valid ASCII.
>>> Which is a silly assumption. However, you are still failing to
>>> initialize pc and pos.

>>
>>
>> Firstly, there's no such thing as a silly assumption in programming.
>> If I say the string has to be all valid ASCII characters, then the
>> string has to be all valid ASCII characters. It's not rocket science.

>
> There *is* such a thing; a silly assumption is a tacit assumption. As
> long as it is well documented, it is fine.


No. A documented "silly assumption" is still a silly
assumption. Documenting garbage code doesn't suddenly make it good
code. However documenting that something takes only ASCII characters is
not any assumption at all - it is a documented limitation/constraint.

>
>> Also, why are you trying to critique my code when you haven't even
>> read it properly? Firstly you critisize the code for not doing three
>> specific things -- three specific things that it wasn't intended to
>> do, and now you can't get your head around the fact that pc and pos
>> are parameters to the original function that I wrote. You'd probably
>> be wise to view the original post before you critique the code further.

>
> It is characteristic of Chuck's posts that he doesn't read the thread
> before butting in. I find it much easier just to killfile him.


Chuck is in most killfiles I would think.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      03-29-2008
Morris Dovey <(E-Mail Removed)> writes:

> Tomás Ó hÉilidhe wrote:
>
>> If any of the chips made an error, there could be a short
>> circuit from 5 V to 0 V which would fry the chips, the power
>> transistors, and also the voltage regulator.

>
>> The finished product has been plugged in constantly
>> overnight for the last two nights and hasn't had a hiccup.

>
> I'm reminded of an early computer cash register system in a gas
> (petrol) station that worked without problem for over a year and
> a half - until a police car pulled in for refueling. Just as the
> car arrived, the dispatcher called on the radio and when the
> policeman responded, his transmitted signal killed the pump
> controller which, in turn, killed the cash register.
>
> It might not be a bad idea to add those inexpensive
> current-limiting resistors...
>
>


Or even better, just shield the electronics properly. You would not put
"current limiting resistors" in either - you would probably use some
active surge detection circuit which dissipates any peak voltages.

 
Reply With Quote
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      03-29-2008
On Mar 29, 1:33*pm, Morris Dovey <(E-Mail Removed)> wrote:

> I'm reminded of an early computer cash register system in a gas
> (petrol) station that worked without problem for over a year and
> a half - until a police car pulled in for refueling. Just as the
> car arrived, the dispatcher called on the radio and when the
> policeman responded, his transmitted signal killed the pump
> controller which, in turn, killed the cash register.
>
> It might not be a bad idea to add those inexpensive
> current-limiting resistors...
>
>



(As of 29th March 2008, 10euro == 16dollars or thereabouts).

When I was testing the board, there was indeed a few short
circuits because there were errors in my code... but none of the
components got fried because I'm using a 2euro power supply that can't
supply more than 300 mA

For items that are extremely well-developed and extremely
reliable, adding something like a fuse actually hurts the device
because the fuse is less reliable than the device! You can get 13 A
fuses that will allow 17 A to flow for a few weeks (and I've seen
them), and then you'll get a 13 A fuse that'll blow for no known
reason. Of all the fuses that have ever blown in my house, I'd say
most of blowings *weren't* caused by excessive current flow but rather
by a tempermental fuse. Add to this the actual cost of each fuse and
the cost of adding it to the circuit board.

For large scale production, I'd hazard a guess that it's more
expensive to put in the resistors/fuses than it is to replace the far-
and-few-between items that get damaged. Think how many 486 computers
there are in the world today that are still running perfectly. People
are buying them off eBay, loading them with two network cards and
Linux, and then using them as a network router. (I was actually at an
auction just there this morning looking to buy a Pentium III laptop
for under 20euro but it turned out to have a smashed screen, I stopped
bidding at 8euro). Digressing tho... now imagine if they saved 1 euro
on every single 486 by taking out some sort of "damage limiting
device" -- I'm sure the 1 euro per unit saving would more than cover
the cost of replacing/repairing the faulty ones.

(I realise a few resitors or even their footprints on the circuit
board won't cost 1euro, but if you consider that all the components on
my board come to a grand total of less than 2euro then I think the
maths works in terms of proportionality)

Of course though, if there's a risk of human harm, or of fire,
etc., then I'd say it's probably best to load the thing with safe
guards. For a small little circuit board tho, the worst you'll get is
a dead microchip. And if it the device is dirt cheap to make, you'd
just send them out a new one rather than repairing it.

And of course, last but certainly not least, it's always fun to
live on the wild side ;-D
 
Reply With Quote
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      03-29-2008
Richard wrote:

> Or even better, just shield the electronics properly.



Strangely enough, I can maul my hands all over the circuit board chips
and connections while the device is on and it doesn't bat an eyelid,
which I was actually quite surprised at


> You would not put
> "current limiting resistors" in either - you would probably use
> some active surge detection circuit which dissipates any
> peak voltages.



The only voltage source on the board is a constant "5 volts DC" so
current-limiting is the way to go, either by means of a fuse or of
current-limiting resistors. Even if you had a few amperes flowing thru
it, the voltage still wouldn't peak -- in fact it would drop because
there'd be a voltage drop across the internal resistance of the power
supply.

In college, we have special power supplies on which you can set a
current limit... which is pretty much an indespensible tool for
testing circuits. I've been on holidays from college for the last two
weeks though so I just went to the Pound Shop and bought an extremely
cheap power supply which also doubles as a current limiter simply by
virtue of the fact that it can't supply more than 300 mA
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      03-29-2008
Tomás Ó hÉilidhe <(E-Mail Removed)> writes:

> Richard wrote:
>
>> Or even better, just shield the electronics properly.

>
>
> Strangely enough, I can maul my hands all over the circuit board chips
> and connections while the device is on and it doesn't bat an eyelid,
> which I was actually quite surprised at
>
>
>> You would not put
>> "current limiting resistors" in either - you would probably use
>> some active surge detection circuit which dissipates any
>> peak voltages.

>
>
> The only voltage source on the board is a constant "5 volts DC" so
> current-limiting is the way to go, either by means of a fuse or of


It's nothing to do with the voltage source "in circuit" AFAICR and in
the example noted at the gas station - the noise from external sources
can cause peaks. And a 5 volt source can easily be stepped up. See
electric pens/lighters for an example :-; Bzzzzz....

> current-limiting resistors. Even if you had a few amperes flowing thru
> it, the voltage still wouldn't peak -- in fact it would drop because
> there'd be a voltage drop across the internal resistance of the power
> supply.
>
> In college, we have special power supplies on which you can set a
> current limit... which is pretty much an indespensible tool for
> testing circuits. I've been on holidays from college for the last two
> weeks though so I just went to the Pound Shop and bought an extremely
> cheap power supply which also doubles as a current limiter simply by
> virtue of the fact that it can't supply more than 300 mA

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert string with control character in caret notation to realcontrol character string. Bart Vandewoestyne C Programming 8 09-25-2012 12:41 PM
Convert an Character to the ASCII Character Code John Gregory Ruby 0 07-05-2009 10:32 PM
How to instantaneously convert array of Integers into an array onint's? Royan Java 32 08-15-2008 02:20 AM
[FR/EN] how to convert the characters ASCII(0-255) to ASCII(0-127) Alextophi Perl Misc 8 12-30-2005 10:43 AM
How to convert CString to an ASCII character string? jt C++ 2 07-14-2005 05:36 AM



Advertisments