May 05, 2024, 06:07:53 AM

News:

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


why am I getting the ascii character set when doing this?

Started by kryton9, July 19, 2006, 06:46:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kryton9

I am getting the ascii character set when this program runs while I was expecting it to print from 0 to 255.

global sub main()
{
   def b as unsigned byte;
   for(b=0; b<256;b++)
   {
      print(b," ",);
      while getkey() ="";// gives you time to see what is happening. I just hold it down till I am done.
   }
   while getkey() ="";// the program doesn't get here, so I just close the window
}

Ionic Wind Support Team

The Print function translates it to a displayable character.  Convert it to an int, or just add zero ;)

print(b+0,"",);

Adding zero elevates it to an integer.  You can also use NumToStr

print(NumToStr(b), "" ,);

Ionic Wind Support Team

kryton9


Protected

Why can't you cast the character to an integer, C-style?

Ionic Wind Support Team

Ionic Wind Support Team

Parker

No, but some type of casting is really needed. Either a new unary operator, like %(int)byte_var, or something like the word "cast" would work - cast(int)byte_var (this is what the D language uses).