User avatar
thagrol
Posts: 4023
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Question about Pi serial numbers

Tue Sep 04, 2018 4:47 pm

Anyone know if Pi serial numbers are case sensitive?

For a project I'm working on I need to compare two serial numbers but I have no idea whether letter case is important. I'm inclined to go with no as they look like a text representation of hex digits but could someone on the inside confirm (or deny) this please.
Arguing with strangers on the internet since 1993.

W. H. Heydt
Posts: 13959
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Question about Pi serial numbers

Tue Sep 04, 2018 5:35 pm

The serial number is a random 32-bit number. If you're seeing what looks like text, then it's probably being shown in hexadecimal. If some of your data is in lower- or mixed-case and you want to get reliable comparison, then do a bit-wise logical OR against spaces and then all the alpha characters will be upper case. FYI...this works in both ASCII and EBCDIC.

User avatar
DougieLawson
Posts: 40512
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Question about Pi serial numbers

Tue Sep 04, 2018 5:40 pm

Hex numbers are not usually case sensitive. Convert it to an unsigned integer compare then convert back.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
thagrol
Posts: 4023
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Question about Pi serial numbers

Tue Sep 04, 2018 5:59 pm

Thanks guys, you've confirmed what I was thinking.
Arguing with strangers on the internet since 1993.

User avatar
Paul Webster
Posts: 833
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
Contact: Twitter

Re: Question about Pi serial numbers

Wed Sep 05, 2018 7:19 am

Converting to integer and comparing will also remove any potential issue with leading zeroes being present or not - i.e. not only a potential case issue.

User avatar
thagrol
Posts: 4023
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Question about Pi serial numbers

Wed Sep 05, 2018 12:48 pm

Yeah, that's what I went with.

If anyone's interested the relevent project is here: https://github.com/thagrol/usb-gadget
Arguing with strangers on the internet since 1993.

Return to “General discussion”