I am getting very strange results when using bitwise operators. I cannot figure out the problem. If anyone can see anything wrong with this code please tell me why the 24th and 25th line of the OutputFile (not the script) are off.
Just Copy and paste this into a text file and load it as a ZScript to see the strange results. (Select Everything between Dots )
:large_orange_diamond:
[IButton,
"Test Bitshift File",
"Test BitShifting",
[MemDelete,tmpBitShiftMem] // make sure mem doesnt exist
[MemCreate,tmpBitShiftMem,1,32] // create string memory
[VarSet,data,0] // data for operations
[VarSet,memSz,0] // keep track of memory size for reallocation
[Loop,32,
[VarSet,data,data|(2^^bit)] // do opperation
//==============================================================>> Make Unsigned
[MemDelete,tmpUnsignMaker]
[MemCreate,tmpUnsignMaker,4,0]
[MemWrite,tmpUnsignMaker,data,6,0]
[MemRead,tmpUnsignMaker,data,6,0]
[MemDelete,tmpUnsignMaker]
//==============================================================>> End Make Unsigned
[VarSet,tmpStr,[StrMerge,bit," : ",data,[StrFromAsc,13]]] // create string for txt file
[VarSet,tmpMemSz,[StrLength,tmpStr]] // get new allocation add
[VarAdd,memSz,tmpMemSz] // keep memoryBlock size
[MemResize, tmpBitShiftMem, memSz , 32] // reallocate memory block
[MemWriteString, tmpBitShiftMem, tmpStr, [Val,memSz-tmpMemSz],0]// write string to mem
,bit //incremental
]
[MemSaveToFile, tmpBitShiftMem, "BitShiftOut.txt",1] // save out to txt.file
[MemDelete,tmpBitShiftMem] // delete memoryBlock
[Note,"Operation Complete"] // Completed
] /* Notes to user*/
Press the button an a file will be made in the folder the script is in.
The File Name is \CFFA000"BitShiftOut.txt"\CB0B0B0. Look at line \CFFA00024 \CB0B0B0and \CFFA00025.
\CB0B0B0I have seen this in other places too, but need to do more tests.
Any Ideas On What this might be.
:large_orange_diamond:
Thanks,
Chris Reid
I attached a more readable version of the script. I hate that the editing structure doesn't work in posts.
Also Attached is the OutputFile. Notice lines <b>24</b> and <b>25
<span class="grey">Attached is also a C++ version of the function. This is what the script should output.
C++ code (MFC)
void CAllTestDlg:small_orange_diamond:OnTest()
{
CString str="C++ Version
==================
",tmp;
CFile f;
if(0==f.Open("BitOut_Cpp.txt",CFile:small_orange_diamond:modeCreate|CFile:small_orange_diamond:modeWrite,NULL))return;
UINT data = 0;
for(int i=0;i<32;i++)
{
tmp.Format("%d : %u
",i,data|=(1<<i));
str+=tmp;
}
f.Write(str,str.GetLength());
f.Close();
}
</span></b> [Here is a temp web link for a more readable version](http://www.rollandberry.com/public/LittleBitOfAProblem_01.txt)
<b>Don't View With NotePad.exe. No LineBreaks show Up.</b>