Count the number of bytes in Hex values in Python - count

I'm new to programming and learning a bit of Python for some engineering related activities so sorry if I'm asking this question in the wrong way.
Is there a way to calculate the number of bytes represented by hex values in Python.
For example, if I have 0x38 (1 byte) and 0x04 (1 byte) is there a way to put these into Python and say the total number of bytes is 2?
Thank you!

Related

Determining a RAMS capacity, with math. (using ram width, word size etc..)

Can some one explain the math behind this.
2 RAMS
16-bits wide
16-bit words
32k 16 bit words is the maximum fill up of each.
How do I get the '32k 16-bit words' from the information provided?
While your question was nearly impossible to understand, I'll try to answer anyway:
32768 16-bit words makes 65536 bytes (8 bits per byte)
2^16 = 65536 = The number of bytes that can be addressed using a 16 bit address.

MIPS; getting the LSB of a hexadecimal value

I understand that there are a few questions already addressing this. However, my question varies in some sort. Suppose I have to get the LSB of a value (hexadecimal) stored in a register; for e.g;
If register $t0 contains the value 0xA4, I need to obtain and store the value 4
If register $t0 contains the value 0xBF, I need to obtain and store the value F
I understand that the bitwise ANDoperation works for decimal values. Could someone please provide some assistance as to how I go about getting the LSB?
Kind regards
You can easily AND the number from which you want to extract the LSB itself like this:
0xA4 AND 0x0F
is same as (in binary)
10100100b AND 00001111
this basically means that only last four digits will be extracted from binary number and that is the LSB you want.
All the binary operations works on general purpose registers along w/ masks which are merely pure numbers (regardless of their underlying basis repr)
Even though x86 isn't MIPS you should have something like this
and EAX, 0xF

What kinds of checksums result in 2 digit hexadecimal?

Is there any checksum that results in 2 digit hexadecimal?
I can only find NMEA Checksum...
references:
http://nmeachecksum.eqth.net/
http://en.wikipedia.org/wiki/NMEA_0183
I have some data file that I want to perform reverse engineering to find the kind of checksum.
Thank you in advance,
Two hex digits is one byte. You're looking for a checksum which produces one byte.
Obviously, you've got a simple additive checksum (sum the bytes of the input), and an xor of the input bytes.
It could also be a longer checksum of which only 8 bits have been taken.
It could also be some kind of CRC-8; Wikipedia knows about five kinds of standardised CRC-8.

LENGTH Field in IEEE 802.11b

I am simulating the IEEE802.11b PHY Model. I am building the header of the Packet in the Physical Layer.
As per the Literature
The PLCP LENGTH field shall be an unsigned 16-bit integer that indicates the number of microseconds to transmit the PPDU.
If I assume the packet size to be 1024Bytes, what should be the value of the Length field(16 bit wide)
The calculation of the LENGTH field depends on the number of bytes to send, as well as on the data rate (5.5 or 11 Mbps). The basic idea of the calculation is:
Bytes * 8
LENGTH = Time (µs) = ----------------
Data rate (Mbps)
However, you need to read Section 18.2.3.5, Long PLCP LENGTH field in the 802.11b-1999 Standard, pages 15-17. It has the complete details of how to calculate this value, along with several examples. It unambiguously explains how to properly round the data, as well as when the length extension bit in the SERVICE field should be set.
I will not reproduce the text of the section here since it looks like IEEE might be strict about enforcing their copyright. However, if you don't have the standard already, I suggest you download it now from the link above -- it's free!
If you have any questions about interpreting the standard, don't hesitate to ask.

One's complement instead of just a sum of bits

A question in my university homework is why use the one's complement instead of just the sum of bits in a TCP checksum. I can't find it in my book and Google isn't helping. Any chance someone can point me in the right direction?
Thanks,
Mike
Since this is a homework question, here is a hint:
Suppose you calculated a second checksum over the entire packet, including the first checksum? Is there a mathematical expression which would determine the result?
Probably the most important is that it is endian independent.
Little Endian computers store hex numbers with the LSB last (Intel processors for example). Big Endian computers put the LSB first (IBM mainframes for example). When carry is added to the LSB to form the 1's complement sum) it doesn't matter if we add 03 + 01 or 01 + 03: the result is the same.
Other benefits include the easiness of checking the transmission and the checksum calculation plus a variety of ways to speed up the calculation by updating only IP fields that have changed.
Ref: http://www.netfor2.com/checksum.html

Resources