Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75498 > unrolled thread
| Started by | bSneddon <w.g.sneddon@gmail.com> |
|---|---|
| First post | 2014-08-01 13:35 -0700 |
| Last post | 2014-08-01 14:25 -0700 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
Creating a 2s compliment hex string for negitive numbers bSneddon <w.g.sneddon@gmail.com> - 2014-08-01 13:35 -0700
Re: Creating a 2s compliment hex string for negitive numbers MRAB <python@mrabarnett.plus.com> - 2014-08-01 21:47 +0100
Re: Creating a 2s compliment hex string for negitive numbers bSneddon <w.g.sneddon@gmail.com> - 2014-08-01 14:25 -0700
| From | bSneddon <w.g.sneddon@gmail.com> |
|---|---|
| Date | 2014-08-01 13:35 -0700 |
| Subject | Creating a 2s compliment hex string for negitive numbers |
| Message-ID | <17160115-a77f-436a-837c-cd2039a7c53f@googlegroups.com> |
I need to calculate an error correction code for an old protocol. I calculate the integer 4617 and want to code the 2s compliment in ASCII hex EDF7. When issue the following. >>> hex(-4617) '-0x1209' Does anyone know a clean way to get to the desired results? My ECC will always be 16 bit (4 nibble) hex number. Bill
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-08-01 21:47 +0100 |
| Message-ID | <mailman.12523.1406926051.18130.python-list@python.org> |
| In reply to | #75498 |
On 2014-08-01 21:35, bSneddon wrote: > I need to calculate an error correction code for an old protocol. > > I calculate the integer 4617 and want to code the 2s compliment in ASCII > hex EDF7. When issue the following. >>>> hex(-4617) > '-0x1209' > > Does anyone know a clean way to get to the desired results? My ECC will always > be 16 bit (4 nibble) hex number. > Use a bitwise AND: >>> hex(-4617 & 0xFFFF) '0xedf7'
[toc] | [prev] | [next] | [standalone]
| From | bSneddon <w.g.sneddon@gmail.com> |
|---|---|
| Date | 2014-08-01 14:25 -0700 |
| Message-ID | <f69f7aca-c744-452b-bbaa-e21699e42b5d@googlegroups.com> |
| In reply to | #75499 |
On Friday, August 1, 2014 4:47:20 PM UTC-4, MRAB wrote: > On 2014-08-01 21:35, bSneddon wrote: > > > I need to calculate an error correction code for an old protocol. > > > > > > I calculate the integer 4617 and want to code the 2s compliment in ASCII > > > hex EDF7. When issue the following. > > >>>> hex(-4617) > > > '-0x1209' > > > > > > Does anyone know a clean way to get to the desired results? My ECC will always > > > be 16 bit (4 nibble) hex number. > > > > > Use a bitwise AND: > > > > >>> hex(-4617 & 0xFFFF) > > '0xedf7' Thanks
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web