May 01, 2024, 10:39:05 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Bytes And Strings

Started by Zen, January 22, 2006, 09:58:38 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Zen

Hi all. Im getting some grief with something im working on at the moment. I have an array of bytes and i want to perform certain things to these bytes then put them all back into a string. Getting them from a string to an array of bytes was a piece of cake but reversing it seemes to be somewhat difficult.

Can anyone help me out here?

Lewis

Bruce Peaslee

It should be simple - what have you tried?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

well i want to be able to print the value of the variable sotred to the console screen so i can see whats in it, so that i can see if my code is right. Ive tried using...

string test;
test = test + byteArray
  • ;

    that doesnt cause any errors but my string is empty when i print it out. I can seem to figure out how to print a byte to the console.

    Lewis

Zen

hmm that byteArray should be byteArray[ x ] without the spaces, must the forum changing it.

Lewis

Zen

Ok for some reason if you try to putput a byte on its own with writeln you get a compile error. If you put + "" after the variable name it works fine. Im not sure if this is intended or not. Just incase anyone was wondering.

Lewis

Bruce Peaslee

That works. I guess WRITELN() expects a string. The compiler gives what I used to call a type mismatch.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

well i did have some problems with my code but i could not figure out where because i couldnt use writeln to putput my bytes. The code is fixed now that i figured out how to get writeln to work with bytes.

Lewis

Bruce Peaslee

I couldn't leave the problem aloneÂÃ,  :-\

I previously bought the Aurora source code and took a look at WRITELN(). I came up with this to write one byte to the console:


// test of output of a single byte

const STD_OUTPUT_HANDLE = -11;

DECLARE IMPORT, WriteFile(
ÂÃ,  ÂÃ,  hFile AS INT,
ÂÃ,  ÂÃ,  lpBuffer AS POINTER,
ÂÃ,  ÂÃ,  nNumberOfBytesToWrite AS INT,
ÂÃ,  ÂÃ,  lpNumberOfBytesWritten AS INT BYREF,
ÂÃ,  ÂÃ,  lpOverlapped AS POINTER
ÂÃ,  ÂÃ,  ),INT;
DECLARE IMPORT, GetStdHandle(handle as INT),int;

global sub main(), int
{
ÂÃ,  ÂÃ,  byte b[10];
ÂÃ,  ÂÃ,  int i;

ÂÃ,  ÂÃ,  for (i=0; i<10; i++)
ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  b[i] = chr$(i+65);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  WriteByte(b[i]);
ÂÃ,  ÂÃ,  }
ÂÃ,  ÂÃ,  while GetKey()="";
ÂÃ,  ÂÃ,  return 0;
}

sub WriteByte(byte out)
{
ÂÃ,  ÂÃ,  int iWritten;
ÂÃ,  ÂÃ,  hOut = GetStdHandle(STD_OUTPUT_HANDLE);
ÂÃ,  ÂÃ,  if hOut <> -1
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  WriteFile(hOut,out,1,iWritten,null);
return;
}



Thanks for the educational opportunity.

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

Cool. Hopefully writeln will be fixed though to allow for outputting bytes.

Glad i could help you with you education bruce ;)

Lewis

Ionic Wind Support Team

January 22, 2006, 12:34:07 PM #9 Last Edit: January 22, 2006, 12:45:19 PM by Ionic Wizard
Writeln isn't broken.  It has one STRING parameter and expects a string variable.

You can use the function CHR$ from the string library if you want to output a single byte.

writeln(chr$(x));

Ionic Wind Support Team

Bruce Peaslee

Quote from: Ionic Wizard on January 22, 2006, 12:34:07 PM
Writeln isn't broken.ÂÃ,  It has one STRING parameter and expects a string variable.

You can use the function CHR$ from the string library if you want to output a single byte.

writlen(chr$(x));



Not broken .. just not enhancedÂÃ,  ;)

I was sure I tried that construction when I was looking at the problem, but I guess not.ÂÃ,  ÂÃ, :-[
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

For some reason i forgot all about ASC and CHR$. I both my recent problems this was the answer.

Lewis