Scott Hanselman

Machine.Shift.Left and Bit Shifting in VB.NET

May 24, '05 Comments [7] Posted in Coding4Fun | Tools
Sponsored By

I was converting some C# 2.0 code for the next Coding4Fun Some Assembly Required to VB.NET. I happened to use an automated C# to VB.NET tool to get me started.

It converted this C# code:

if( (btData - '0') <= 9)
{
   receivedChecksum = (byte)((btData - '0') << 4);
}
else
{
   receivedChecksum = (byte)((btData - 'A' + 10) << 4);
}

Into this attempt at VB.NET code.

If btData - "0" <= 9 Then
   
receivedChecksum = System.Convert.ToByte(Machine.Shift.Left((btData - "0"), 4))
Else
  
receivedChecksum = System.Convert.ToByte(Machine.Shift.Left((btData - "A" + 10), 4))
End If

Of course, Machine.Shift.Left (and .Right) doesn't exist. Looks like something that the convertor folks missed? Perhaps they forgot to implement?

At any rate, you can use the standard bit shifting << and >> operators in VB.NET 2.0 like this.

If btData - "0" <= 9 Then
   
receivedChecksum = System.Convert.ToByte((btData - "0") << 4)
Else
   
receivedChecksum = System.Convert.ToByte((btData - "A" + 10) << 4)
End If

And I continue forward...

UPDATED:

You might think that VB.NET would let you use ^= if you can << and >>.

Well, it will compile things like

foo ^= bar

But the ^= operator means Power Of in VB, not Xor as I thought it should. Doh! I'm out of VB.NET practice.

VB.NET folks, I'm sorry, but when it comes down to manipulating raw Bytes, the language sucks.

foo = foo Xor bar

And I continue forward...

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

UML 2.0 Diagrams and Shape Downloads for Microsoft Visio

May 23, '05 Comments [0] Posted in Ruby
Sponsored By

I was out looking for UML Shapes for Microsoft Visio today. I knew I had found them before, but I couldn't find them for the life of me. Chris Brooks reminded me of Pavel Hruby's most excellent Visio Stencil and Template for UML 2.0 downloads.

He's got versions going all the way back to Visio 4.1, and more importantly he's got one for Visio 2003. He offers them as a free service but appreciates donations via PayPal.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

GuildWars and the ErgoDex DX1

May 22, '05 Comments [6] Posted in Reviews | CodeRush | Gaming
Sponsored By

Guildwarsergodex

Not only am I digging GuildWars more than any game since HL2 and Doom3, but I'm really enjoying it with the new ErgoDex DX1 (I mentioned this device last year).

The ErgoDex is, for lack of a better word, a Macro Pad. It's an 8x10 pad that most folks mistake for a Wacom Tablet when they pass by. However, it's got 25 loose (wireless) keys that adhere to its surface. They are kind of RFID-y and have unique numbers (i.e. they are addressable). It ships with keys 1 to 25 and you can buy 26-50 as an accessory. The keys have magic stickum underneath and twist off easily. If they get dirty you can wipe them and the stickum comes back.

Additionally, their user-interface for the recording of macros (single key, multi-key with or without timing and/or key concurrency) is fantastic. I've got lots of gamepads (don't we all) with all sorts of crap interfaces for macros and key bindings. This one just works. You can drag and drop or you can just click the ErgoDex key you want to assign, then the key or keys on the main keyboard it should emulate.

Ergodex2The other sweet thing about it is the ad-hoc macro recorder. There's a hardware button on the pad that starts and stops recording. You can throw temporary macros onto a key, type on the main keyboard, then finish. Subsequent presses on the ErgoDex key play back what you did with timings.

Like any good pad of any kind (mouse, stylus, etc), you can pop off the clear top and put a skin underneath it. Their software includes a shiny manager program that lets you create all sorts of underlays. I haven't had this much fun since I created home-made overlays for my Vectrex.

I've also used my ErgoDex at work along with CodeRush to have one button access to refactoring, class creation, quick navigation and a number of other VS.NET HotKeys.

Why have a pad like this you ask? There's a few simple reasons:

  • A keyboard is designed for prose, not hotkeys. The whole F1-F12 thing is a hack and we never get F1 anyway. Eleven lousy keys unless we want to hold down Ctrl-Alt-Shift?
  • I personally play one game at a time until I'm sick of it. The ErgoPad can change whenever I want it to, but this one will stay in this config until the next game I dig. There are a bunch of peripherals available like the failed Microsoft Strategic Commander. It failed for a reason. It was obtuse and only made sense for Age of Empires (and hardly then).

I like the idea of a totally custom controller/keypad for absolutely any reason I like. The ErgoDex also comes with Macro support for all the Microsoft Office apps and it even detects things you've got installed. It automatically set up profiles for FarCry and Doom 3.

I also like the idea of putting the keyboard elsewhere out of site and gaming with just this specialized pad (25 keys that are set up the way I want rather than 101 keys that are set up like a typewriter) and the mouse.

I hate being I/O bound by the hardware I interface to the computer with. I'd like to use pads, mice, voice and pens all at the same time.

Recommended for the serious gamer anyone serious about interfacing with their computer effectively.

UPDATE#1: There's a bootleg RSS Feed for the GuildWars.com site as they don't have one.

Now playing: Black Eyed Peas - Hey Mama

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

May 2005 - What is Scott up to?

May 19, '05 Comments [25] Posted in TechEd | ASP.NET | Coding4Fun | XML | Africa | Tools
Sponsored By

I've been a little heads down lately. Sorry about that. I've been slow to blog. However, here's a short list of the things that have been on my mind lately. (Also, I WILL be updating the Ultimate Tools List, but I want to do it justice, so bear with me.)

What has been on my mind this last week, in no particular order:

  • I updated my Linksys Router from Sveasoft Alchemy to the new Sveasoft Talisman Firmware.
    • Man, it is freaking shiny. It's Alchemy++, indeed. This new update includes a roughly 3meg read-write area of flash for external programs to be downloaded. Remember, the Linksys router is just a tiny Linux box. You can PuTTY into it and everything.
    • Things that kick ass about this firmware. You can VPN into your home. You can setup Quality of Service (QoS) to make sure that the wife's Vonage call to Zimbabwe doesn't get kicked because of your massive pr0n downloads. You can easily assign specific IPs to specific MACs. Way easier than static IP addressing. There are a pile more. It's truly changed my whole home network and made it WAY easier to manage. Yum.
  • GuildWars is truly the most amazing RPG I've ever played. Ya ya, EverQuest, ya ya, Diablo, whatever. This is the total package. From purchase to download to play to continued play, it's perfect. Why?
    •  73 KB (yes KB) client to download, ala Steam, that streams just the levels and content you need now. No waiting for 40 Gigs to download. It's fast and it's brilliant.
    • Graphics. This thing scales like nobody's business. I mean, it's good on my Dx9 ATI 9600, but it's even good on my craptastic laptop.
    • You can you actually run it in a Window. How many times have you pissed off a DirectX app when some Blue Toast popped up or you accidentally Alt-Entered. GuildWars will scale as you resize it. Stunning.
    • No local storage of your folks. That means I can pop the small client on my wife's system and fire it up. My character (Abeba Oluchi, a Warrior/Elementalist, thank you very much) is right where I left 'em.
    • Graphics. Did I mention wheat that sways in the wind?
    • Simple to buy. Gave them US$50 at http://plaync.com/store/gw_purchase.html and I was off. Seemless. Smoother than Steam and Half-Life 2.
    • I'm still doing my thing on the Some Assembly Required column. I still love that title. Coming soon? I've got NMEA 2.0 GPS code in .NET 2.0, Media Center fun, more Phidgets, a CrystalFontz display with input buttons, possibly some Legos, possibly some Robots, some iPodity perhaps, and something with Windows Image Acquisition.
  • Professional ASP.NET 2.0. We're still cranking away on the book. We're making sure everything is technically accurate and insightful and ready for the final builds when they come.
    • I'm pretty happy with the Caching chapter, the chapter on State Management and the chapter on XML in the context of ASP.NET 2.0. I've also got some good information while reading Oleg's blog. Seriously, if you care about XML, you need to know this guy. Unsubscribed, then RSS subscribed again, just to reinforce it. :)
  • Jamaica. We just got back from a Cruise from Miami to Jamaica.
    • Turns out I'm not a cruise person. We don't smoke. We don't drink. We don't eat in excess. Seems that is what you're paying for, so perhaps we didn't get our money's worth.
    • I was more interested in talking about how the World Bank and the Chiquita Banana lobby has destroyed the Jamaican economy, but other cruisers were more interested in bidding on velvet paintings of dolphins.
    • SO, I might have been a bit of a drag. That said, I got tan-esque, learned about this new kind of shoe that people who relax call a "flip-flop" and read Angels and Demons by Dan Brown.
      • It was so much better than the crap Da Vinci code. Really, if you liked Da Vinci Code, Angels and Demons (the prequel) will cause you to implode.

I will leave you, Dear Reader (both of you) with this. I've got potentially big news coming. I shall leave you to speculate wildly. Discuss.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.