User avatar
thagrol
Posts: 1981
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.
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

W. H. Heydt
Posts: 11067
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: 36540
Joined: Sun Jun 16, 2013 11:19 pm
Location: 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.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
thagrol
Posts: 1981
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.
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

User avatar
Paul Webster
Posts: 812
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: 1981
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
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

Return to “General discussion”