May 02, 2024, 04:46:40 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Practical typecasting tricks

Started by WayneA, June 15, 2010, 11:57:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

WayneA

Type RGBColor
Dim Red As Char
Dim Green As Char
Dim Blue As Char
Dim nul As Char
EndType

Dim a,b As Int

a=RGB(255,125,75) 'Red 255, Green 125, Blue 75
Print "Red:\t",Int(*<RGBColor>(&a).Red)
Print "Green:\t",Int(*<RGBColor>(&a).Green)
Print "Blue:\t",Int(*<RGBColor>(&a).Blue)
b=0x004B7DFF 'Red FF, Green 7D, Blue 4B
Print "-\nRed:\t",Hex$(*<RGBColor>(&b).Red)
Print "Green:\t",Hex$(*<RGBColor>(&b).Green)
Print "Blue:\t",Hex$(*<RGBColor>(&b).Blue)

Type Integer
Dim LoWord As Word
Dim HiWord As Word
EndType

Dim c As Int

c=0x04121912 'day titanic sank I believe...
Print "-\nHiWord:\t0",Hex$(*<Integer>(&c).HiWord),"\t|\t0",Hex$(HIWORD(c))
Print "LoWord:\t",Hex$(*<Integer>(&c).LoWord),"\t|\t",Hex$(LOWORD(c))
Do:Until Inkey$<>""

Sub LOWORD(in As UInt),Word
Return in & 0xFFFF
EndSub

Sub HIWORD(in As UInt),Word
Return (in >> 16) & 0xFFFF
EndSub
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

aurelCB

What tis program exactly do..?
I recive only this after compiling
QuoteCompiling...
WayneTypeCast.eba
File: C:\Program Files\EBDev\projects\WayneTypeCast.eba (11) syntax error - &
File: C:\Program Files\EBDev\projects\WayneTypeCast.eba (12) syntax error - &
File: C:\Program Files\EBDev\projects\WayneTypeCast.eba (13) syntax error - &
File: C:\Program Files\EBDev\projects\WayneTypeCast.eba (15) syntax error - &
File: C:\Program Files\EBDev\projects\WayneTypeCast.eba (16) syntax error - &
File: C:\Program Files\EBDev\projects\WayneTypeCast.eba (17) syntax error - &
File: C:\Program Files\EBDev\projects\WayneTypeCast.eba (27) syntax error - &
File: C:\Program Files\EBDev\projects\WayneTypeCast.eba (28) syntax error - &
Error(s) in compiling "C:\Program Files\EBDev\projects\WayneTypeCast.eba"

WayneA

Honestly, I'm not sure why this won't compile for you. I'm using EBasic IDE 1.737/Compiler 1.735. If you are using the same version then I would make sure theres no additional spaces from copy/pasting from the forums.

This program demonstrates how you can typecast standard built-in variables (only ints in this example) and pick them apart in a meaningful way using structured types.
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

aurelCB

Sorry man my mistake i try on 1.737 and work.I first try on old 1.62