Coding

Welcome, Guest. Please login or register.
Did you miss your activation email?
August 19, 2017, 11:52:28 AM

Login with username, password and session length

Menu

Members
Stats
  • Total Posts: 12135
  • Total Topics: 1730
  • Online Today: 66
  • Online Ever: 195
  • (February 11, 2014, 12:46:08 PM)
Users Online
Users: 0
Guests: 35
Total: 55
Yahoo!
Sogou
Google
Baidu (17)

Recent Topics

Pages: [1]   Go Down

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

0 Members and 1 Guest are viewing this topic.

TLaRoche

  • Newbie
  • *
  • Bananas: 0
  • Offline Offline
  • Gender: Male
  • Posts: 9
  • 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
Logged
Just finished backing up to the ol' tape backup drive ... again. Maybe this time restore will work...

Larry McCaughn

  • Head Monkey
  • Administrator
  • Sr. Member
  • *****
  • Bananas: 4
  • Offline Offline
  • Gender: Male
  • Posts: 254
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
Logged
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)

TLaRoche

  • Newbie
  • *
  • Bananas: 0
  • Offline Offline
  • Gender: Male
  • Posts: 9
  • 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.
Logged
Just finished backing up to the ol' tape backup drive ... again. Maybe this time restore will work...

Larry McCaughn

  • Head Monkey
  • Administrator
  • Sr. Member
  • *****
  • Bananas: 4
  • Offline Offline
  • Gender: Male
  • Posts: 254
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
Logged
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)

TLaRoche

  • Newbie
  • *
  • Bananas: 0
  • Offline Offline
  • Gender: Male
  • Posts: 9
  • 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.
Logged
Just finished backing up to the ol' tape backup drive ... again. Maybe this time restore will work...
Pages: [1]   Go Up
 

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

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