* *

Coding

User

Welcome, Guest. Please login or register.
June 26, 2017, 12:11:13 PM

Login with username, password and session length

Menu

Stats

Members
Stats
  • Total Posts: 12120
  • Total Topics: 1727
  • Online Today: 81
  • Online Ever: 195
  • (February 11, 2014, 12:46:08 PM)
Users Online
Users: 0
Guests: 31
Spiders: 20
Total: 51
Exabot
Baidu (19)

Author Topic: Trying to translate the (C) HIWORD macro ti IB Std  (Read 1278 times)

0 Members and 1 Guest are viewing this topic.

Offline TLaRoche

  • Newbie
  • *
  • Posts: 9
  • Bananas: 0
  • Gender: Male
  • Born to code ... doomed to fail...
Trying to translate the (C) HIWORD macro ti IB Std
« on: August 22, 2015, 03:04:39 AM »
Hello all,

I'm trying to implement the C language HIWORD macro to IBasic Std, and I'm not quite getting it...
Code: [Select]
' Emulated macro declaration
Declare HIWORD (dwValue:Int)

....

Sub HIWORD (dwValue)
Def ret:Word

ret = ((Val (Str$ (dwValue))) / 2^16) & 0x0FFFF
Return ret
As you can see with this latest version of the macro -- I'm converting the value to a string, then taking the "Val" of that, but it just isn't working right (I think at the Str$ statement).

Thanks in advance,
Tochillo
Just finished backing up to the ol' tape backup drive ... again. Maybe this time restore will work...

Offline Larry McCaughn

  • Head Monkey
  • Administrator
  • Sr. Member
  • *****
  • Posts: 253
  • Bananas: 4
  • Gender: Male
Re: Trying to translate the (C) HIWORD macro ti IB Std
« Reply #1 on: August 22, 2015, 06:48:13 AM »
if you are looking for the value of the high 16 bits then


Declare HIWORD (dwValue:Int)
def ret:int
 ret = (dwValue >> 16) && 0x0FFFF
return ret
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline TLaRoche

  • Newbie
  • *
  • Posts: 9
  • Bananas: 0
  • Gender: Male
  • Born to code ... doomed to fail...
Re: Trying to translate the (C) HIWORD macro ti IB Std
« Reply #2 on: August 24, 2015, 07:53:04 PM »
Hi Larry,

Thank you for responding. I am not getting the right output from the proc you posted (which I tried to exhaustion before the version that I posted above.

I'm wondering if I should declare a UINT in the proc and see if I get the right output when the siign bit is high... I'll have to try it out later when I get back to my system. I'll try to post the results either way for the sake of sharing knowledge.

Thanks again for responding.
Just finished backing up to the ol' tape backup drive ... again. Maybe this time restore will work...

Offline Larry McCaughn

  • Head Monkey
  • Administrator
  • Sr. Member
  • *****
  • Posts: 253
  • Bananas: 4
  • Gender: Male
Re: Trying to translate the (C) HIWORD macro ti IB Std
« Reply #3 on: August 25, 2015, 12:14:42 AM »
my bad, this is really all you need
Code: [Select]
SUB HiWord(iWord as UINT),UINT
NewWord = iWord >> 16
RETURN NewWord
ENDSUB

Code: [Select]
SUB LoWord(iWord as UINT),UINT
NewWord = iWord & 0xFFFF
RETURN NewWord
ENDSUB
Admin - Here and @ Ionic Wind Software Forums
Author of Custom Button Designer, Custom Chart Designer, Snippet Manager, and IWB+ (A Visual Designer for IWBasic 2.x)

Offline TLaRoche

  • Newbie
  • *
  • Posts: 9
  • Bananas: 0
  • Gender: Male
  • Born to code ... doomed to fail...
Re: Trying to translate the (C) HIWORD macro ti IB Std
« Reply #4 on: August 28, 2015, 09:22:40 AM »
Would believe it ... my system fan blew I'm on one of my laptops for the moment. LOL  ::)

I will try it ASAP. Like I wrote in my last post, I suspected that I would need to declare a UINT. I was thinking a little more like this code (to make it a little more agreeable with the rest of the code:
Code: [Select]
Declare HIWORD (iWord:INT), WORD

......

Sub HIWORD (iWord)
Def NewWord:UINT
NewWord = (iWord / (2^16))
Return NewWord

Hopefully, this will allow my (INT) vars to pass through with ease.

Thanks again for your help with this problem.
Just finished backing up to the ol' tape backup drive ... again. Maybe this time restore will work...

 

To link to us use this code/button on your site

http://www.codingmonkeys.com/images/cm_link.gif