• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Base256 to int

Does anybody know how to convert a string (base 256 number) to integer?
0
TiborKi
Asked:
TiborKi
  • 3
  • 2
2 Solutions
 
aikimarkCommented:
How big is the string?
The ciuly link is probably the easiest solution.
0
 
TiborKiAuthor Commented:
the string is 4 bytes
0
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!

 
aikimarkCommented:
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
 
TiborKiAuthor Commented:
well, it must be fast...
0
 
aikimarkCommented:
"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

Independent Software Vendors: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now