Ask Dave Taylor
  • Facebook
  • Instagram
  • Linkedin
  • Pinterest
  • Twitter
  • YouTube
  • Home
  • YouTube Videos
  • Top Categories
  • Subscribe via Email
  • Ask A Question
  • Meet Dave
  • Home
  • Linux Shell Script Programming
  • Linux Script to Create Amateur Radio Call Signs?

Linux Script to Create Amateur Radio Call Signs?

June 5, 2019 / Dave Taylor / Linux Shell Script Programming / No Comments

Hi Dave! In amateur radio we have a server that converts 7 digit numbers to shorter numbers based on the last 16 bits of their binary value. This is due to a 65518 number limit in NXDN. I would like to add the numbers to the database to display the correct call sign. Help!

I have to admit, this one took some back and forth communication to fully understand. Here’s the deal: Amateur radio (also known as ham radio) is built atop some pretty old school computer tech, so there are lots of 60’s and 70’s era elements. One of which is the continued reliance on 16-bit numerical call signs. Why 16-bits? Because that’s the double-byte integer storage capacity: 16 on/off slots. A single byte is just 8 binary values, and has a range of 0-256. 16-bits gets you 0-65535 (not 65518). You can calculate these yourself: 2**8 and 2**16.

Modern 32-bit systems have a considerably bigger MAXINT of 4,294,967,296 and if you’re writing a 64-bit program, your maximum integer value might be a whopping 1.844674407E19. Be that as it may, however, a question is a question, so let’s dig in…

I’m going to solve all of this as a Linux shell script but since it’s using basic scripting (with one exception) it’ll work fine in Windows or Mac if you can get to the Bash shell. Don’t have a Bash shell but have /bin/sh? You’ll need to tweak one line, but I’ll identify that shortly.

ham amateur radio setup

Here’s some sample input and output: Given 5054035 that should convert to 7763. How? By converting 5054035 to binary -> 10011010001111001010011, then chopping off the last 16 digits -> 0001111001010011 and then converting that back from binary into decimal.

That’s exactly how the script will work too.

First off, most conversions from one base to another can be easily accomplished in the powerful bc command:

longbinary="$(echo "obase=2;$1" | bc)"

Remember that $( … ) is a subshell, so we’re converting the given value – $1 – and saving it in the variable longbinary. Next step is to chop the last 16 digits off, and that’s done with a nifty trick: reverse the binary number, cut off the first 16 digits, then reverse it again to restore the proper order. Easier than figuring out the last n characters of a sequence:

last16="$(echo $longbinary | rev | cut -c1-16 | rev)"

And, finally, to convert that binary value back to decimal, let’s utilize an obscure Bash notational convention:

result="$((2#$last16))"

The $(( … )) loads the mathematics system in Bash, then 2# as a prefix indicates the value given is base 2, or binary. By default, it converts from binary to decimal, and voila! the solution.

I’ll put it all together in a script:

#!/bin/sh

# given a long HAM radio identifier, convert it to binary
# then grab the last 16 digits and convert that back to decimal

if [ -z "$1" ] ; then
echo "Usage: $0 RadioIdentifier" ; exit 1
fi

longbinary="$(echo "obase=2;$1" | bc)"
last16="$(echo $longbinary | rev | cut -c1-16 | rev)"
result="$((2#$last16))"

echo "input : $1"
echo "in binary: $longbinary"
echo "last 16 : $last16"
echo "result : $result"

exit 0

And that’s it. Now on the command line it’s easy to convert from those long amateur radio values to a digital call sign:

$ ham16.sh 5054035
input : 5054035
in binary: 10011010001111001010011
last 16 : 0001111001010011
result : 7763

Not too tricky once you understand the problem, right?

Want to learn more about amateur radio? No better place to start than ARRL, the national association for amateur radio!

Pro Tip: I’ve written quite a bit about how to solve complex problems with Linux shell scripts. While you’re here, please check out my linux shell script help area for lots more tutorials!

About the Author: Dave Taylor has been involved with the online world since the early days of the Internet. Author of over 20 technical books, he runs the popular AskDaveTaylor.com tech help site. You can also find his gadget reviews on YouTube and chat with him on Twitter as @DaveTaylor.

Let’s Stay In Touch!

Never miss a single article, review or tutorial here on AskDaveTaylor, sign up for my fun weekly newsletter!
Name: 
Your email address:*
Please enter all required fields
Correct invalid entries
No spam, ever. Promise. Powered by FeedBlitz
Please choose a color:
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!
amateur radio, amateur radio call sign, call sign calculator, call sign converter, ham radio, ham radio call sign, linux script, shell script

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Recent Posts

  • Everything You Need to Know about Apple’s Clean Energy Charging
  • How Can I Watch Free Classic Movies on my Windows PC?
  • How Can I Maximize Online Privacy with a VPN Connection?
  • SCAM: Did I Just Buy A Computer From Amazon? I Demand a Refund!
  • How Can I Stop My AirPods Pro Making Beeps and Noises?

On Our YouTube Channel

iClever Bluetooth 34-Key Number Pad Keyboard -- REVIEW

Google Pixel 7 Pro Android Smartphone - UNBOXING

Categories

  • AdSense, AdWords, and PPC Help (106)
  • Amazon, eBay, and Online Shopping Help (164)
  • Android Help (228)
  • Apple iPad Help (147)
  • Apple Watch Help (53)
  • Articles, Tutorials, and Reviews (346)
  • Auto Tech Help (17)
  • Business Advice (200)
  • ChromeOS Help (33)
  • Computer & Internet Basics (782)
  • d) None of the Above (166)
  • Facebook Help (384)
  • Google, Chrome & Gmail Help (188)
  • HTML & Web Page Design (247)
  • Instagram Help (49)
  • iPhone & iOS Help (625)
  • iPod & MP3 Player Help (173)
  • Kindle & Nook Help (99)
  • LinkedIn Help (88)
  • Linux Help (174)
  • Linux Shell Script Programming (90)
  • Mac & MacOS Help (914)
  • Most Popular (16)
  • Outlook & Office 365 Help (33)
  • PayPal Help (68)
  • Pinterest Help (54)
  • Reddit Help (19)
  • SEO & Marketing (82)
  • Spam, Scams & Security (96)
  • Trade Show News & Updates (23)
  • Twitter Help (222)
  • Video Game Tips (66)
  • Web Site Traffic Tips (62)
  • Windows PC Help (951)
  • Wordpress Help (206)
  • Writing and Publishing (72)
  • YouTube Help (47)
  • YouTube Video Reviews (159)
  • Zoom, Skype & Video Chat Help (62)

Archives

Social Connections:

Ask Dave Taylor


Follow Me on Pinterest
Follow me on Twitter
Follow me on LinkedIn
Follow me on Instagram


AskDaveTaylor on Facebook



microsoft insider mvp


This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to our terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. Our lawyer says "Thanks for your cooperation."
© 2023 by Dave Taylor. "Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.
Privacy Policy - Terms and Conditions - Accessibility Policy