Solved

Base256 to int

Posted on 2006-10-24
8
614 Views
Last Modified: 2008-02-01
Does anybody know how to convert a string (base 256 number) to integer?
0
Comment
Question by:TiborKi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 125 total points
ID: 17796908
0
 
LVL 45

Expert Comment

by:aikimark
ID: 17798414
How big is the string?
The ciuly link is probably the easiest solution.
0
 
LVL 1

Author Comment

by:TiborKi
ID: 17798517
the string is 4 bytes
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Expert Comment

by:aikimark
ID: 17798626
The only problem you are likely to encounter is signed versus unsigned integer values.  If the high-order bit of the high-order byte = 1 then a signed integer will be negative.

Is this a performance critical function or do you simply need to know how it can be done?
0
 
LVL 1

Author Comment

by:TiborKi
ID: 17798790
well, it must be fast...
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 125 total points
ID: 17798999
"fast" is relative.  The best course of action will be to try the ciuly linked solution and determine if it suits your needs as far as functionality and speed.  If it doesn't, then ask us for more help.

===================================
For future readers, there are several approaches available to do this conversion.
* character->ord add and shiftLeft 8 (three statement pairs followed by simple add)
* similar to above, but using For iteration construct
* Delphi Copy function or API call to copy bytes directly into integer variable.  May require additional ntohl API call to reverse the byte order to accomodate Little-endian Windows environment.  This solution can get really tricky, depending on the nature of the 'string variable'.  Due to complexity, this should be solution approach of last resort.
* ASM solution (see the FastCode project)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question