Half precision floating point question — smallest non-zero number

There’s a floating point question that popped up and I’m confused about the solution. It states that

IEEE 754-2008 introduces half precision, which is a binary
floating-point representation that uses 16 bits: 1 sign bit, 5
exponent bits (with a bias of 15) and 10 significand bits. This format
uses the same rules for special numbers that IEEE754 uses. Considering
this half-precision floating point format, answer the following
questions: ….

What is the smallest positive non-zero number it can represent?

bias = 15
Binary representation is: $$0 , 00000 , 0000000001 = 2^{-14} * 2^{-10}=2^{-24}$$

I’ve understood the binary representation part, but how does it get to those exponents of 2??

authentication – Why does message 1 of the WPA2 4 way handshake begin with the access point sending a random number?

All the references I have found

https://en.wikipedia.org/wiki/IEEE_802.11i-2004

4-Way Handshake

EAPOL 4-Way Handshake

indicate that the first thing that happens is the sending of the Anonce( a random number) from the access point to the client.
This communication carries no information and could have come from any attacker.
The client then constructs message 2 with this formula:
PTK = PRF (PMK + Anonce + SNonce + Mac (AA)+ Mac (SA))
Now the access point can create message 3 to return to the client.

Since the access point kicked off the whole process with just a random number, How does the client know that the access point is genuine and not a spoof? Somewhere I am missing where the 4 way handshake proves the access point’s authenticity.

c – Check if point is inside a bitmap shape

Inspired by this question, here’s some C code to check if a point is “inside” of a shape on a simple black and white bitmap.

For this exercise:

• Set bits form the “outlines” of a shape (and are never inside).
• Unset bits may be inside or outside of a shape.
• Unset bits with a path to the edge of the bitmap are “outside”.
• Unset bits with no path to the edge of the bitmap are “inside”.
• Paths may step diagonally between set bits.

``````
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void die() { __debugbreak(); }
void die_if(bool condition) { if (condition) die(); }

struct bitmap
{
size_t m_w;
size_t m_h;
bool* m_pixels;
};

struct bitmap bitmap_from_string(size_t width, size_t height, char const* str)
{
die_if(!str);
die_if(strlen(str) != width * height);

bool* pixels = malloc(sizeof(bool) * width * height);
die_if(!pixels);

char const* src = str;
bool* dst = pixels;

char const set = "https://codereview.stackexchange.com/#";
for (size_t i = 0; i != width * height; ++i)
*dst++ = (*src++ == set ? true : false);

return (struct bitmap){ width, height, pixels };
}

bool bitmap_is_in_bounds(struct bitmap* bmp, size_t x, size_t y)
{
die_if(!bmp);
return (x < bmp->m_w) && (y < bmp->m_h);
}

bool bitmap_at(struct bitmap* bmp, size_t x, size_t y)
{
die_if(!bmp);
die_if(!bitmap_is_in_bounds(bmp, x, y));

return bmp->m_pixels(y * bmp->m_w + x);
}

bool bitmap_is_at_edge(struct bitmap* bmp, size_t x, size_t y)
{
die_if(!bmp);
die_if(!bitmap_is_in_bounds(bmp, x, y));

return (x == 0 || y == 0 || x == (bmp->m_w - 1) || y == (bmp->m_h - 1));
}

void bitmap_free(struct bitmap* bmp)
{
die_if(!bmp);

free(bmp->m_pixels);
bmp->m_pixels = NULL;
}

/* bitmap_is_in_shape
*    A "shape" is composed of unset bits, fully enclosed (on axes and
* diagonally) by set bits (so there should not exist a path of unset bits from
* the start point to the edge of the bitmap).
*    Start points on set bits are not considered to be "inside" a shape.
*/
bool bitmap_is_in_shape(struct bitmap* bmp, size_t x, size_t y)
{
die_if(!bmp);
die_if(!bitmap_is_in_bounds(bmp, x, y));

/* trivial rejection */
if (bitmap_at(bmp, x, y)) return false; /* on outline */
if (bitmap_is_at_edge(bmp, x, y)) return false; /* at edge */

/* depth first search */
struct coords { size_t x, y; };

size_t stack_size = 0;
struct coords* stack = malloc(sizeof(struct coords) * bmp->m_w * bmp->m_h); /* coords to visit next */
die_if(!stack);

bool* visited = calloc(bmp->m_w * bmp->m_h, sizeof(bool)); /* points added to stack - indexed the same as bitmap pixels */
die_if(!visited);

visited(y * bmp->m_w + x) = true; /* start point already visited */

/* for each neighbour... */
#define N(c_x, c_y)
X(c_x, c_y, -1, -1)
X(c_x, c_y, -1,  0)
X(c_x, c_y, -1, +1)
X(c_x, c_y,  0, -1)
X(c_x, c_y,  0, +1)
X(c_x, c_y, +1, -1)
X(c_x, c_y, +1,  0)
X(c_x, c_y, +1, +1)

/* check visited list and push to stack */
#define X(c_x, c_y, o_x, o_y)
if (!visited((size_t)(c_y + o_y) * bmp->m_w + (size_t)(c_x + o_x)))
{
visited((size_t)(c_y + o_y) * bmp->m_w + (size_t)(c_x + o_x)) = true;
stack(stack_size++) = (struct coords){ (size_t)(c_x + o_x), (size_t)(c_y + o_y) };
}

N(x, y); /* add neighbours */

bool result = true;

while (stack_size != 0)
{
struct coords c = stack(--stack_size); /* pop */

if (bitmap_at(bmp, c.x, c.y)) continue; /* on outline */
if (bitmap_is_at_edge(bmp, c.x, c.y)) { result = false; break; } /* at edge */

N(c.x, c.y); /* add neighbours */
}

#undef X
#undef N

free(stack);
free(visited);

return result;
}

void test(bool expected, bool actual, char const* name)
{
printf("%s: %sn", name, (expected == actual ? "pass" : "FAIL"));
}

int main()
{
{
struct bitmap bmp = bitmap_from_string(1, 1, "#");

test(false, bitmap_is_in_shape(&bmp, 0, 0), "one pixel - set");

bitmap_free(&bmp);
}
{
struct bitmap bmp = bitmap_from_string(1, 1, " ");

test(false, bitmap_is_in_shape(&bmp, 0, 0), "one pixel - unset");

bitmap_free(&bmp);
}
{
struct bitmap bmp = bitmap_from_string(3, 3,
"###"
"# #"
"###");

test(false, bitmap_is_in_shape(&bmp, 0, 1), "three pixel - on outline");
test(true, bitmap_is_in_shape(&bmp, 1, 1), "three pixel - bounded");

bitmap_free(&bmp);
}
{
struct bitmap bmp = bitmap_from_string(3, 3,
"###"
"# #"
"## ");

test(false, bitmap_is_in_shape(&bmp, 0, 1), "three pixel - on outline");
test(false, bitmap_is_in_shape(&bmp, 1, 1), "three pixel - middle w/ outlet");

bitmap_free(&bmp);
}
{
struct bitmap bmp = bitmap_from_string(8, 4,
"########"
"###### #"
"#      #"
"########");

test(true, bitmap_is_in_shape(&bmp, 1, 2), "corridor - start");
test(true, bitmap_is_in_shape(&bmp, 6, 1), "corridor - end");
test(false, bitmap_is_in_shape(&bmp, 3, 1), "corridor - on outline");

bitmap_free(&bmp);
}
{
struct bitmap bmp = bitmap_from_string(8, 4,
"##### ##"
"###### #"
"# #    #"
"########");

test(true, bitmap_is_in_shape(&bmp, 1, 2), "corridor - room");
test(false, bitmap_is_in_shape(&bmp, 3, 2), "corridor - start");
test(false, bitmap_is_in_shape(&bmp, 6, 1), "corridor - end");
test(false, bitmap_is_in_shape(&bmp, 3, 1), "corridor - on outline");

bitmap_free(&bmp);
}
}

``````

Some things:

• The X macro was fun to use… but feels a little messy. Especially adding the offset to the coordinates.

• I like to use assert-type checks (`die_if()`) everywhere… but is it too much? Often there’s a check in a higher-level function (e.g. `bitmap_is_in_shape()` checks that the bitmap isn’t null) that makes all the following lower-level checks redundant (e.g. in `bitmap_at()` checks it again).

Would having two versions of lower-level access functions (e.g. `bitmap_at()` and `bitmap_at_unsafe()`) be silly?

• Any other C-ish things (especially more modern stuff) that’s missing?

Any other feedback welcome. 🙂

Anyone Ever Used Digital Point?

I have not ever tried advertising with Digital Point

For advertising, I would go with WebmasterSun
It has good active members and high traffic site also you can advertise on it with low price.

Hope it helps!

women role in share point improvement

http://spraydeal.com
in my life I feel that woman love money a lot and sometime woman kick money for a man I am too much confused what is this?

c – Determine if a point is inside or ouside of an irregular shape on a bitmap

You are given an irregular shape on a bitmap. How do you determine if
a point is inside or ousdie of the shape?

We are allowed to assume that `helper functions` are already available for us and we don’t need to write them as well.

So I decided that I can use a function that returns me the status of a given bit on that bitmap.

``````int IsBitIsOn(bitmap_ty *bitmap, size_t x, size_t y);
``````

We also can assume that the given point won’t be a point on the outline of the shape. Which means the given X,Y coordinates must be either inside or outside the shape and not on one of the outlines.

And here is my full code of the task,
I wrote it as a bitmap that every `ON(==1)` bit tells me that I’m on an outline, while `0 bit` tells me i’m either `inside` or `outside` the shape.

``````int IsInTheShape(bitmap_ty *bitmap, size_t x, size_t y)
{
int IsIn = 0; /* flag of whether the given point is inside the shape    */

int ComeFromAbove = 0;

int start_sequal = 1;

size_t curr_row = y;
size_t curr_column = 0;

while (x != curr_column)
{
if (IsBitIsOn(bitmap, curr_column, curr_row))
{
IsIn = !IsIn;

/* starts a sequal of bits that are ON  */
while (IsBitIsOn(bitmap, curr_column + 1, curr_row))
{
/* checks the source direction of the first bit in the sequal */
if (start_sequal &&
IsBitOn(bitmap, curr_column, curr_row - 1) ||
isBitOn(bitmap, curr_column - 1, curr_row - 1) ||
isBitOn(bitmap, curr_column + 1, curr_row - 1))
{
ComeFromAbove = 1;
start_sequal = 0;
}
++curr_column;
}
/*  checks the source direction of the last bit in the sequal,
so if it cuts the direction of the first bit, it means
the next points are out of the shape    */
if (ComeFromAbove)
{
if (!IsBitOn(bitmap, curr_column, curr_row + 1) &&
!isBitOn(bitmap, curr_column - 1, curr_row + 1) &&
!isBitOn(bitmap, curr_column + 1, curr_row + 1))
{
ComeFromAbove = 0;
IsIn = !IsIn;
}
}
}
++curr_column;
}

return (IsIn);
}
``````

I draw the following shapes find the problematic points and shapes:

point and shoot – Dust on the sensor vs. in the lens?

I have an old, used Panasonic LX100 (Point and Shoot) that I plan to use as my main all-use video camera. I just started noticing that dust spots are visible in the image on apertures larger than about 4, and they become sharper as aperture is increased.

I have a couple of questions. First of all, would this indicate that the dust is on one of the lens elements, on the sensor, or either?

Second, if I were to have this commercially repaired, would either repair be substantially harder than the other? I’m keeping cost in mind as I might just get an ND filter to avoid using the higher apertures if the cost is too high for my practicality (at least until I save up to have the repair done).

Find tangent line going through a point outside the curve in multivariable calculus

Determine the equations for all lines tangent to the ellipse

$$f(x,y)=x^2+xy+y^2=1$$

and passing through the point (0,2)

I’m a bit stuck on this question.
I was thinking if I have an unknown point on the curve called (a.b). Then I can plug it in the curve.
$$f(a.b)=a^2+ab+b^2=1$$
And if I also find the derivative of it, which is:
$$(2a+b,a+2b)$$
But from here I really don’t know how to proceed. Maybe if I can somehow set it up as simultaneous equations and find the unknown point, from there I can easily find the tangent line.

trigonometry – Relational distance in terms of axis to another point

Lets say we are in a fighter jet and we know our current position in 3D space (x,y,z, x=EW gps, y=NS gps, z=Height), our direction in degrees (0-360, 0 = north, 90 is east, 180 south, 270 west), our inclination (0-180, 0 = straight down, 90 = horizontal, 180 = straight up).

Now let’s say we have a flight plan that we should be following. We have the flight plan positions in 100′ discretized increments.

I am looking for 3 equations respectively to calculate the distance from my current position in 3D space to the flight plan in terms of up/down, left/right, forward/back. So this is the results I am looking for 500 feet ahead:

Up/Down Diff, Left/Right Diff, Forward/Back Diff
(3, -10, 0),
(5, -12, 100),
(7, -14, 200),
(9, -16, 300),
(11, -18, 400),
(13, -20, 500)

I am essentially creating a 3d perspective plane from the front seat of my cockpit depending on my inclination/direction and then relationally needing to calculate the distance from where I should be at that moment to where I should be in 100′ and 200′ and etc.

camera – Horizontal and vertical field of view calculation when principal point is not image center

I have a requirement to calculate the ground footprint for an aerial camera. I have the camera position and orientation. To calculate it, I require to calculate Horizontal Field of View (FoV) and vertical FoV. I found the formulas in calculating horizontal FoV and vertical FoV. But the formulas assume that the principal point is in the image center (I hope).

What are the correct formulas to apply when the principal point is not the image center? In my case, the principal point deviates from the image center.

Does principal point have an impact on calculating Horizontal FoV and Vertical FoV?