?
Solved

How to convert binary data to string

Posted on 2003-03-10
7
Medium Priority
?
288 Views
Last Modified: 2010-04-04
 Registry.RootKey := HKEY_CURRENT_USER;
  Registry.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\Folder',False)
   Registry.ReadBinaryData('VALUE7', Buffer , Sizeof(Buffer))
  How to convert binary data to string.

0
Comment
Question by:rsivam
[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
7 Comments
 
LVL 7

Expert Comment

by:billious
ID: 8109349
Sort of depends on what precisely you want to do with the string (display it? store it? manipulate it?) and how long that string is (using the shortstring 'string' type, youhave a maximum of 255 characters.)

so you could try
var s : string; i : integer;

i := readbinarydata(.....);
s := '';
while i > 0 do
  s := char(buffer[i]) + s; {assuming buffer is an array of byte}

which may give you a string of non-ASCII characters

or
...
while i > 0 do
  s := hex2(buffer[i]) + s; {assuming buffer is an array of byte}


and hex2 is something like

function hex2(b : byte) : string[2];
const
  hexchars : array[0..15] of char = ('0','1','2',
                                     '3','4','5',
                                     '6','7','8',
                                     '9','A','B',
                                     'C','D','E','F');
begin
  hex2 := hexchars[b div 16] + hexchars[b mod 16];
end;

...it all really depends on what you mean!

...Bill
0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8110233
Carry out below method, you can use buffer var as string.

var Registry: TRegistry;
   Buffer   : array[1..255] of char;
   isize : Integer;
begin
  Registry := TRegistry.Create;

  Registry.RootKey := HKEY_LOCAL_MACHINE;
  Registry.OpenKey('\SOFTWARE\Prn\DEMO2',False);
  iSize := sizeof(Buffer);
  Registry.ReadBinaryData('PASSWD', Buffer, isize);
  Registry.Free;
  Buffer[isize] := #0;
  ShowMessage(buffer);
end;
0
 
LVL 7

Accepted Solution

by:
billious earned 1000 total points
ID: 8111286
Not neccessarily, I fear merry_prince!

This is one of the downfalls of ASCIIZ strings - they don't take to internal-nulls very well.

The returned series of bytes MAY contain an internal null, so your showmessage would show a string terminated at that point. Remember, a readbinarydata gets a series of bytes that can be ANY value - such as a serial number encoded as a straight binary.

...Bill
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:rsivam
ID: 8116738
Dear Mr.millious

Thank u for your detailed mail.
My aim is tio find the current open dir in explorer.

When i  read the binary data stored in
\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\Folder',

 i := Registry.ReadBinaryData('Value1', Buffer, isize);

it returns the value 0 for all  values stored in the folder.

pls. give your  idea reg. How to get the current open
directory.


























0
 

Expert Comment

by:CleanupPing
ID: 9316850
rsivam:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 10091009
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: billious

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

771 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